开发者

Jquery :not selector not working in ie

I have the following html code:

<ul>
                <li class="O">
                    <label for="radio1">Radio 1:</label>
                    <input type="radio" name="radio1" value="Yes" checked>Yes</input>
                    <input type="radio" name="radio1" value="No">No</input>
                </li>
                <li class="O">
                    <label for="checkbox1">Checkbox 1:</label>
                    <input type="checkbox" name="checkbox1" id="checkbox1" value="check"></input>
                </li>
            </ul>

Using jQuery I'd like to do something with each checkbox not checked or element with an empty value inside an li element with class O. This is my approach:

$('li').each(function(){
        if ($(this).hasClass('O')){
            $(this).children(':not(label,input:radio)').each(function(){
                if ( $(this).val() == "" || $(this).is(':checkbox:not(:checked)') ) {
                    //do something
                }
            });
        }

This code is working on FF, Opera, Chrome and Safari, but not in IE6-IE7.

With both IEs, getting the length of the li's with $(this).children(':not(label,input:radio)').length returns 2 , other browsers return 0 and 1.

Also, getting the first li's number of children that are not a label ($(this).children(':not(label)').length) returns 4, while getting the number of children ($(this).children().length) returns 2. It makes no sense to me at all.

Am I wrong or is there something in the selector I used开发者_StackOverflow社区 that is not fully compatible with IE?

Thanks in advance.


If I understand correctly you try to manipulate checkboxes that are not checked and are inside a li with class O. I have no IE to test, but I simplified it a bit. Can you try it?

$('li.O').each(function(){
    $(this).children(':checkbox:not(:checked)').each(function(){
        //stuff
    });
});

Update: Based on the comment, you can try this:

$('li.O').each(function(){
    $(this).children(':checkbox:not(:checked), :not(label,input:radio)[value=]').each(function(){
        //stuff
    });

});

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜