当我尝试在 jQuery 中修改 DOM 时,代码停止工作
我正在尝试修改 DOM 元素,但由于某种原因代码被卡住了。
var length = tabOne.length;
for(var i = 0; i < length; i++) {
if(tabOne[i] == sPage){
alert("In Tab One");
// Set the top nav link as current (Get the first link in #nav-main)
$("#nav-main a:first").addClass("current");
// Set the sub nav link as current (Find it by URL)
$("a[href='" + sPage + "']").addClass("current");
// Show the sub nav
$("#nav-sub-welcome").css('display', '');
alert("We got this far");
}
}
该脚本永远不会在最后显示警报。我尝试注释掉特定的操作,但由于某种原因,除非将它们全部注释掉,否则警报不会运行。任何帮助表示赞赏!
I am trying to modify DOM elements but for some reason the code gets jammed up.
var length = tabOne.length;
for(var i = 0; i < length; i++) {
if(tabOne[i] == sPage){
alert("In Tab One");
// Set the top nav link as current (Get the first link in #nav-main)
$("#nav-main a:first").addClass("current");
// Set the sub nav link as current (Find it by URL)
$("a[href='" + sPage + "']").addClass("current");
// Show the sub nav
$("#nav-sub-welcome").css('display', '');
alert("We got this far");
}
}
The script never displays the alert at the end. I tried commenting out specific manipulations but for some reason the alert wont run unless they are all commented out. Any help is appreciated!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是使用此代码的页面也在加载原型,并且它们发生冲突。 阅读本文以了解如何避免冲突。
The problem was that the page this code was being used on was also loading prototype, and they conflicted. Read this to learn how to avoid conflicts.