开发者

How do I set a radio button value using jQuery?

开发者 https://www.devze.com 2023-01-07 06:09 出处:网络
I have the following Radio Buttons: <form id=\"bg\" action=\"#\"> <span id=\"questionText\">Question Test Here:</span><br/>

I have the following Radio Buttons:

         <form id="bg" action="#">
            <span id="questionText">Question Test Here:</span><br/>
            <input type="radio" name="bga"><span id="A1"></span></input><br/>
            <input type="radio" name="bga"><span id="A2"></span></input><br/>
            <input type="radio" name="bga"><span id="A3"></span></input><br/>
            <input type="radio" name="bga"><span id="A4"></span><开发者_如何学运维;/input><br/>
            <input type="button" name="btn" id="btn" value="OK!"/>
         </form>

I want to be able to set the values of each individual radio button with a different value using jQuery.


var i=0;
$(':radio', $('#bg')[0]).each(function() {
  $(this).attr('value', i++).text("Option " + i);  // value=0, text="Option 1", etc.
});


You can give each radio element an id then $("#id").attr("value", "thevalueyouwant") for each one.

0

精彩评论

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