jQuery - 在全局变量中设置的元素匹配在 Google Chrome 中不起作用
我在仅适用于 Google Chrome 的代码中发现了一个可疑的故障。我已经定义了几个变量作为我经常引用的一些元素,并且除了在 Google Chrome 中之外,执行代码没有任何问题(我花了很长时间才弄清楚是我的变量导致了问题)。我想知道是否有人知道为什么会发生这种情况。
以下代码在 Mozilla 中运行良好,但在 Chrome 中则不然:
var homeAbout = $("#homeAbout");
$("#subLinkAbout").bind("click", function() {
if (homeAbout.is(":visible")) {
return;
}
$("#content .homeNode:visible").hide("slide", { direction: "right" }, contentSlideTime, function () {
//this line does not function properly
homeAbout.stop(true, false).show("slide", { direction: "left" }, contentSlideTime);
});
});
但是,这工作正常:
var homeAbout = $("#homeAbout");
$("#subLinkAbout").bind("click", function() {
if (homeAbout.is(":visible")) {
return;
}
$("#content .homeNode:visible").hide("slide", { direction: "right" }, contentSlideTime, function () {
$("#homeAbout").stop(true, false).show("slide", { direction: "left" }, contentSlideTime);
});
});
这似乎只发生在使用 .show() 的一行上。内容将被隐藏,然后什么也不会发生。谁能进一步解释这一点?对我的代码的任何建议也非常感谢,我在 jQuery 方面仍然很新手......
提前非常感谢,任何建议都会受到赞赏。
I've found a suspicious glitch in my code native only to Google Chrome. I had defined several variables as some elements I commonly referenced, and had no problems executing the code except when in Google Chrome (took me quite awhile to figure out that my variables were causing the issue). I am wondering if anyone knows why this is happening..
The following code runs fine in Mozilla, but not in Chrome:
var homeAbout = $("#homeAbout");
$("#subLinkAbout").bind("click", function() {
if (homeAbout.is(":visible")) {
return;
}
$("#content .homeNode:visible").hide("slide", { direction: "right" }, contentSlideTime, function () {
//this line does not function properly
homeAbout.stop(true, false).show("slide", { direction: "left" }, contentSlideTime);
});
});
This however, works fine:
var homeAbout = $("#homeAbout");
$("#subLinkAbout").bind("click", function() {
if (homeAbout.is(":visible")) {
return;
}
$("#content .homeNode:visible").hide("slide", { direction: "right" }, contentSlideTime, function () {
$("#homeAbout").stop(true, false).show("slide", { direction: "left" }, contentSlideTime);
});
});
This only appears to happen on the one line where .show() is used. The content will be hidden, and then nothing will happen afterwards. Can anyone explain this further? Any suggestions on my code are also greatly appreciated, I am still very novice when it comes to jQuery...
Thanks very very much in advance, any advice is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用 jQuery 为什么要使用绑定?
应该会更好。
If you are using jQuery why are you using bind?
Should be better.