使用JQuery,我的目标是:
<li style="margin-left: 15px;">blah<li>使用此代码:
$(".block-category-navigation li[style='margin-left: 15px;']").addClass('sub-menu');它在firefox中运行良好,但在IE中根本不起作用。 IE会忽略样式选择器吗? 无论如何,如果是这样
With JQuery, I am targeting the following:
<li style="margin-left: 15px;">blah<li>with this code:
$(".block-category-navigation li[style='margin-left: 15px;']").addClass('sub-menu');It works great in firefox, but doesn't work at all in IE. Does IE ignore the style selector? Anyway around if so
最满意答案
在IE8的控制台中查看后,我发现它正在将'margin-left'变成'MARGIN-LEFT'。
在IE中,这个选择器可以工作:
$(".block-category-navigation li[style='MARGIN-LEFT: 15px']").addClass('sub-menu');您可以同时使用大写和小写选择器,也可以使用循环来检查样式属性,如下所示:
$('.block-category-navigation li[style]').each(function() { $this = $(this); if ($this.attr('style').match(/margin-left: 15px/i)) { $this.addClass('sub-menu'); } });UPDATE
既然我不想给你不起作用的代码,我在这里设置了这个工作示例: http : //jsfiddle.net/YB7uV/6/
After checking this in IE8's console, I found that it's turning 'margin-left' into 'MARGIN-LEFT'.
In IE this selector will work:
$(".block-category-navigation li[style='MARGIN-LEFT: 15px']").addClass('sub-menu');You could either have both upper & lower case selectors, or use a loop to check the style attribute like so:
$('.block-category-navigation li[style]').each(function() { $this = $(this); if ($this.attr('style').match(/margin-left: 15px/i)) { $this.addClass('sub-menu'); } });UPDATE
Since I don't want to give you code that doesn't work, I've setup this working example here: http://jsfiddle.net/YB7uV/6/
更多推荐
style,IE,px,firefox,JQuery,电脑培训,计算机培训,IT培训"/> <meta name="de
发布评论