<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta charset="utf-8">
<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
</head>
<body>
<h2>获取被选中的radio值</h2>
<hr>
<input type="radio" name="fileType" value="1" />1<br />
<input type="radio" name="fileType" value="2" />2<br />
<input type="radio" name="fileType" value="3" />3<br />
<button οnclick="getRadioValue()">测试</button>
<h2>获取当前 radio 是否被选中</h2>
<hr>
<input type="radio" name="r1" id="r1"/>
<button οnclick="checkSelected('r1')">是否选中</button>
<hr>
<h2>设置可用和不可用</h2>
<input name="testdisable" type="radio" id="set1" value="1"/>
<input name="testdisable" type="radio" id="set2"value="2" />
<input name="testdisable" type="radio" id="set3"value="3" />
<button οnclick="setDisable()">设置不可用</button>
<button οnclick="setEnable()">设置可用</button>
<button οnclick="getSelectedRadioValue()">获取被选中值</button>
<script>
function getRadioValue() {
var radioValue = $('input[name="fileType"]:checked').val();
alert(radioValue);
}
function checkSelected(obj) {
var checkedVal = $("#" + obj).attr("checked");
alert(checkedVal)
if(checkedVal=='checked'){
alert("被选中");
} else {
alert("未选中");
}
}
function setDisable() {
$('input[name="testdisable"]').each(function (){
$(this).attr("disabled", true);
});
}
function setEnable() {
$('input[name="testdisable"]').each(function (){
$(this).attr("disabled", false);
});
}
function getSelectedRadioValue() {
var radioValue = $('input[name="testdisable"]:checked').val();
alert(radioValue);
}
</script>
</body>
</html>
radio 使用
最新推荐文章于 2023-02-02 17:22:45 发布