为什么仅在 IE 中查询失败

发布于 2024-11-15 05:40:07 字数 1104 浏览 2 评论 0原文

我的查询运行得很好,但是当我在 IE 上检查它时,结果是一场灾难。我想知道它是否是代码的父部分。父母正在尝试访问第一个包含该信息的。有没有更简单的方法可以直接到达餐桌?

 <script>
 if ($('b:contains("Choose a sub category:")').length > 0) {
 var newSubnav = document.createElement( 'ul' );
 $(newSubnav).addClass("sub_categories_holder");
  $('b:contains("Choose a sub category:")').parent().parent().parent().parent().parent().parent().parent().prepend( newSubnav );

 $('a.subcategory_link').appendTo($('ul.sub_categories_holder'));
 $('a.subcategory_link').wrap("<li class='sub_categories'></li>");
 $('li.sub_categories').before("<li class='sub_categories_divider'></li>");
 $("li.sub_categories_divider:eq(0)").remove();

 $("b:contains('Choose a sub category:')").parent().parent().parent().parent().parent().remove();
 $("img[src='/v/vspfiles/templates/GFAR NEW NAV/images/Bullet_SubCategory.gif']").remove();
 $("td.colors_backgroundneutral").css("background-color","transparent");
 $("td.colors_backgroundneutral").children(':first-child').attr("cellpadding","0");
 };

 </script>

My query works great, but then I check it on IE and it is a disaster. I am wondering if it is the parent part of the code. The parents are trying to reach the first <table> containing the info. Is there an easier way to get to the table directly?

 <script>
 if ($('b:contains("Choose a sub category:")').length > 0) {
 var newSubnav = document.createElement( 'ul' );
 $(newSubnav).addClass("sub_categories_holder");
  $('b:contains("Choose a sub category:")').parent().parent().parent().parent().parent().parent().parent().prepend( newSubnav );

 $('a.subcategory_link').appendTo($('ul.sub_categories_holder'));
 $('a.subcategory_link').wrap("<li class='sub_categories'></li>");
 $('li.sub_categories').before("<li class='sub_categories_divider'></li>");
 $("li.sub_categories_divider:eq(0)").remove();

 $("b:contains('Choose a sub category:')").parent().parent().parent().parent().parent().remove();
 $("img[src='/v/vspfiles/templates/GFAR NEW NAV/images/Bullet_SubCategory.gif']").remove();
 $("td.colors_backgroundneutral").css("background-color","transparent");
 $("td.colors_backgroundneutral").children(':first-child').attr("cellpadding","0");
 };

 </script>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情栀口红 2024-11-22 05:40:07

除非你提供你的标记(至少是一个虚拟的标记),否则一切都是猜测你会得到的。

  1. 而不是 .parent().parent().parent().parent().parent().parent().parent().prepend( newSubnav ); 检查是否可以使用 .parents()。这会将父项一直返回到 HTML。您甚至可以使用选择器作为父级(选择器)来进行过滤。在 jquery api 页面上了解更多信息。

  2. 由于您使用的是 jQuery,因此您可以使用 $("ul") 而不是 document.createElement("ul")

Unless you provide your markup(at least a dummy one) it's all guess that you are gonna get.

  1. Instead of .parent().parent().parent().parent().parent().parent().parent().prepend( newSubnav ); check if you can use .parents(). This will return you the parents all the way up to HTML. You can even use selectors as parents(selector) to filter. Read more on the jquery api page.

  2. Since you are using jQuery, you can use $("ul") instead of document.createElement("ul")

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文