I am trying to set a radio button. I want set it by using the value or the id.
This is what I've tried.
$('input:radio[name=cols]'+" #"+newcol).attr('checked',true);
newcol is the id of the radio button.
Maybe a little edit is in order.
There are two sets of radio boxes one with cols and the other with rows. So I see the point in not using id's. My bad. So I have as an example:
style="width: 50%; " value="Site">
and
style="width: 50%; " value="Site">
with the id's removed, and I need to set the correct one.
解决方案
Your selector looks for the descendant of a input:radio[name=cols] element that has the id of newcol (well the value of that variable).
Try this instead (since you're selecting by ID anyway):
$('#' + newcol).prop('checked',true);
Also, as of jQuery 1.6 the perferred method of altering a property is .prop(): http://api.jquery.com/prop