I have radio buttons in HTML like this:
1
-
Finally after a lot of tests, I think the most convenient and efficient way to preset is:
var presetValue = "black";
$("input[name=correctAnswer]").filter("[value=" + presetValue + "]").prop("checked",true);
$("input[name=correctAnswer]").button( "refresh" );//JQuery UI only
The refresh is required with the JQueryUI object.
Retrieving the value is easy :
alert($('input[name=correctAnswer]:checked').val())
Tested with JQuery 1.6.1, JQuery UI 1.8.
- 热议问题