我有一个 div,一开始是隐藏的,单击按钮时会显示。 div上还有一个按钮,onclick事件调用这个函数:
function popuppage2OK() {
alert("you clicked ok!");
var x = new Object();
x.name = $("#boxforname").val(); //this is a text input
x.option = $("#boxforoption").val();//this is a text input
alert("hiding newfactorpage2");
$("#popupform").hide(); //this is a div containing the text inputs and the button with the onlcick event that calls this function
alert("popupform hidden");
displaystuff(); //another function ive written that needs to be called
alert("this is after the display attempt");
}
我的问题是,唯一执行的行似乎是隐藏 div 的行。没有任何警告框出现,并且 Displaystuff() 函数不会被执行,但 div 会恢复隐藏状态。关于为什么代码行可能会像这样被跳过的任何想法?
最佳答案
什么时候将事件处理程序附加到 div 内的按钮?
您应该在页面加载完成后执行此操作,因此在 Jquery 中您可以执行以下操作:
$(document).ready(function () {
//attach the eventhandler here
})
关于Javascript函数只执行一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6848964/