js设置单选按钮选中/取消示例代码
用jquery的代码设置,第一次有效果,第二次就没效果了,所以用百度了一下,用js原生代码设置就行!
<!DOCTYPE html PUBLIC "-/W3C/DTD HTML 4.01 Transitional/EN" "http:/www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>主页</title>
<script type="text/javascript" src="jquery-easyui/jquery.easyui.min.js"></script>
</head>
<body>
<input type="text" id="valText" />
<input type="radio" name="payMethod.names" value="true" id="radio1" />支付宝
<input type="radio" name="payMethod.names" value="false" id="radio2" />财务通
<button οnclick="radioVal();">值</button>
<script type="text/javascript">
function radioVal(){
//获取valText的值,进行判断需要选中哪个!!
var valText = $("#valText").val();
var country = document.getElementsByName('payMethod.names');
for(var i=0;i<country.length;i++){
if(valText == 0){
if(country[i].value == "false")
{
country[i].checked=true; //选中
//country[i].checked=false; //不选中
}
}else{
if(country[i].value == "true")
{
country[i].checked=true; //选中
//country[i].checked=false; //不选中
}
}
}
}
</script>
</body>
</html>