开发者

jquery .map function

I am trying to read checkbox values using jquery .map like below:

var cars=$("#carsid input[name=car]:checked").map(function(){

return $(this).val();)).get().join(',');

But above code throwing length is null or not an object.I dont understand,what is the iss开发者_运维知识库ue here.Can anyone give hints?

Regards,

Raj


Your script contains some syntax errors. Additionally, you want to do the .get().join(',') on the whole object when it is returned, not on each individual element. Try changing it to this:

var cars = $("#carsid input[name=car]:checked").map(function() {   
    return $(this).val();
}).get().join(',');

My change is to remove the extra ;)) after $(this).val(). Then I moved .get().join(',') to operate on the returned jQuery object, rather than each element.

Here is a demo showing this in action ->


you're selecting on carsid, which isn't a tag. You probably want a # before it if it's an ID, or a . if it's a class.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜