jQuery显示div,然后消失 [英] jQuery showing div and then Disappearing
问题描述
如果这是一个简单的问题,我会提前道歉,我有以下javascript代码:
I apologize ahead of time if this is a simple question, I have this javascript code:
$(document).ready(function() {
$("#results").hide();
var html = $.ajax({ url: "ajax.php?db_list=get", async: false}).responseText;
$("#submit").click(function () {
$("#results").show();
});
});
我有一个看起来像这样的按钮:
I have a button that looks this:
<fieldset class="action">
<button name="submit" id="submit">Submit</button>
</fieldset>
当我单击提交"按钮时,我想显示结果div并将其保留在那里,但是在Chrome中它会弹出然后立即消失,这是因为文档顶部的hide()函数已经准备好了?
When I click on the Submit button I wanted to show the results div and have it stay there, but in Chrome it pops up and then immediately disappears, is this because of the hide() function at the top of my document ready?
谢谢!
推荐答案
...这是因为我的文档顶部的hide()函数已经准备好了吗?
...is this because of the hide() function at the top of my document ready?
可能是.我猜页面正在刷新.如果您不想这样做,请在处理程序中使用return false;
.
Probably. I'm guessing the page is refreshing. If you don't want that, use return false;
in the handler.
$("#submit").click(function () {
$("#results").show();
return false;
});
$("#submit").click(function ( event ) {
$("#results").show();
event.preventDefault();
});
这篇关于jQuery显示div,然后消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!