单选框选中值获取以及设置某个选中

radio选中的值获取

HTML:

	<input type="radio" name="sex" id="sex" value="男" />男
	<input type="radio" name="sex" id="sex" value="女" />女

获取:
js:var sex=$("input[name='sex']:checked").val();

多个单选框默认选中:

var radios=$("input[name='sex']");
	if (res.sex=="男") {
		radios.eq(0).attr("checked", true);
	} else{
		radios.eq(1).attr("checked", true);
	}

猜你喜欢

转载自blog.csdn.net/qq_33327325/article/details/82803202