开发者

Getting selected radio button value here

I have html in my form that looks like this开发者_运维技巧. First, is this code malformed or something? Second, when the selected radio changes, how do I get the value of the selected radio? I do $('#form_options').change(function(){ }); but what goes inside to get the value of the selected button

<div id="form-options">
   <label for="options">Choose an option</label>

   <Label for="morning">
      <input type="radio" name="options" id="options-morning" value="morning" />Morning
   </label> 
   <label for="options-night">
      <input type="radio" name="options" id="options-night" value="night" />Night
   </label>
   <label for="options-evening">
      <input type="radio" name="options" id="options-evening" value="evening" />Evening
   </label>
</div>


Your div id is wrong. You need $('#form-options') instead of $('#form_options')

Try this:

$('#form-options').change(function() {
    alert($('input[name=options]:checked').val());
});

You can try it here - http://jsfiddle.net/FloydPink/PF8qX/


Try this:

$("input[@name='options']", '#form-options').change(function(){
    console.log($(this).val());
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜