前端: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);
posted @ 2019-01-11 11:16  xuejianbest  阅读(5498)  评论(0编辑  收藏  举报