开发者

JQuery, getting value of checked radio button, why is this not working?

I am trying like below to get the value of a checked radio button but it just keeps giving undefined. I am using Firefox on Ubuntu so I don't know if its some weird quirk of the browser or what, I would appreciate any advice as this is driving me crazy:

            <input name="tagRow_ddd" type="radio" value="p">
                <input name="tagRow_ddd" type="radio"开发者_开发百科 value="r">


alert($('input[name=tagRow_ddd]:checked').val())

Jfiddle: http://jsfiddle.net/fD7fP/6/


that's exactly the output it should give. the :checked selector only finds checked elements... you haven't any.

http://jsfiddle.net/fD7fP/7/


Because by default nothing is checked. If you have either checked by default it works.

Check working example at http://jsfiddle.net/fD7fP/8/


You need to quote the attribute value http://api.jquery.com/attribute-equals-selector/

So it should be

alert($("input[name='tagRow_ddd']:checked").val())


Try making one selected by default. Lke so

<input name="tagRow_ddd" type="radio" value="p">
<input name="tagRow_ddd" type="radio" value="r">
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜