这种类型的交互应该使用Javascript实现,因为它是客户端操作。
HTML:
<form>
<input type="radio" name="radio1" value="yes"/>Yes
<input type="radio" name="radio1" value="no"/>No
<br />
<input type="radio" name="radio2" value="yes"/>Yes
<input type="radio" name="radio2" value="no"/>No
<br />
<input type="radio" name="radio3" value="yes"/>Yes
<input type="radio" name="radio3" value="no"/>No
<br />
<input type="button" value="Select All" onclick="selectAll('radio',true);"/>
<input type="button" value="Deselect All" onclick="selectAll('radio',false);"/>
</form>
的Javascript:
function selectAll(prefix, set) {
var form = document.forms[0], //Get the appropriate form
i = 0,
radio;
while(radio = form[prefix + ++i]) //Loop through all named radio# elements
for(var j = 0; j < radio.length; j++) //Loop through each set of named radio buttons
if(radio[j].value == (set ? "yes" : "no")) //Selector based on value of set
radio[j].checked = true; //Check that radio button!
}
JSFiddle
你应该使用JavaScript来做到这一点。 –