前端:radio单选按钮
单选按钮
<label><input type="radio" name="radio1" value="1" />选项1</label>
<label><input type="radio" name="radio1" value="2" />选项2</label>
<label><input type="radio" name="radio1" value="3" />选项3</label>
单选按钮互斥是通过相同的name
属性实现的。
var selector;
//返回被选择radio的value属性值
function whichRadioValueChecked(selector){
var rtn = "";
selector.each(function(){
if($(this).prop("checked")){
rtn = $(this).attr("value");
}
});
return rtn;
}
selector = $('input[type="radio"][name="radio1"]');
var value = whichRadioValueChecked(selector);