$(document).ready(function() {
var x = "";
$("#anyElement").click(function() {
x = "test";
alert(x);
});
alert(x);
});
当第一次警报的作品,消息框,显示“测试”。当第二次提醒工作时,messagebox显示“”。如何在点击事件中设置全局变量?
$("#anyElement").click(function() {
// How can i set the x veriable as "test" here
});
全局是坏 – morissette 2014-10-27 19:54:51
代码看起来很好......你肯定第一个警报没有'“”'? – tymeJV 2014-10-27 19:55:11
这是由于变量的范围。 – 2014-10-27 19:55:53