I have the following code
<input type="radio" name="HotelSearch_Measure" value="Miles">
<input type="radio" name="HotelSearch_Measure" value="KM">
However when I use t开发者_开发问答he following it works in IE9/Chrome/Firefox but not in IE6
jQuery("input[value='Miles'").attr("checked", true);
I've tried searching with no luck.
Thanks in advance.
I believe this will work for IE6 and for the other browsers also
jQuery("input[value='Miles']").attr("checked", "checked");
If you are using jQuery < 1.6
do this:
jQuery("input[value='Miles']").attr("checked", 'checked');
If you are using jQuery 1.6+:
jQuery("input[value='Miles']").prop("checked", true);
See this question: .prop() vs .attr() and Possible bug in jQuery 1.6 - $(...).attr("checked") is not working for references why.
Provided your typo (jQuery("input[value='Miles']").attr("checked", true);
) occurred when typing your question, and isn't present in your live code, what you have is the correct way to do it, prior to jQuery 1.6.0.
With the new version however, the new method prop()
should be used:
jQuery("input[value='Miles']").prop("checked", true);
jQuery 1.6+ uses prop() like this:
jQuery('input[value="Miles"]').prop("checked", true);
精彩评论