开发者

Checkbox Issue with IE8 using jquery

I have this code

 $('#Submit').click(function(event) {
            var checked = $('.inputchbox'); ......IE8
            var ids= checked.map(function() {
                return $(this).val();
            }).get().join(',');
             alert(ids);
        });

This Code return all the values which is there for Checkboxbox (.inputchbox is class for the checkbox)

but If I give somethign like this

var checked = $('.inputchbox input:checkbox:checked');
or
var checked = $('.inputchbox input[type=checkbox]:checked');
or
var checked = $('.inputchbox input[name=chk]:checked');
or 
var checked = $('.inputchbox').find('input[type=checkbox]:checked');

if i am giving like this nothing is working for me I am not getting the result in IE8?

 v开发者_如何学Pythonar checked = $('.inputchbox'); .....this is working but I am getting the checkboxes ids its doesnot checking wheather its checked or not.. 

I need to get only checked chekcbox id's

thanks


How about

var checked = $('.inputchbox:checked');

? The problem with your snippets is that the space you're using is the descendant selector and will look down into the DOM. The .find() method does the same. g.d.d.c was correct in replying that .filter() instead of .find() should work equally well (but a marginal amount slower):

var checked = $('.inputchbox').filter(':checked');


When you include a space in your selector it implies children. If you want to get by class with attributes you need to do something like this: $('.inputchbox:checked')


A space in a selectors indicates an ancestor-descendant relationship, i.e. .inputchbox is an ancestor of your checkbox, which from your other example, seems incorrect.

Try:

$('input.inputchbox:checkbox:checked');

Etc.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜