必须有一步是click事件,网上看到其他的依然会报错,要把其他的checked的属性去除
<html>
<head>
<script type="text/javascript" src="./jquery/jquery-1.12.3.min.js"></script>
</head>
<body>
<div>
<input id="yes" name="radio" type="radio" value="1" checked="checked"/>是
<input id="no" name="radio" type="radio" value="0"/>否
<div>
<script type="text/javascript">
$(function(){
$("#btn1").click(function(){
$("input[name='radio']").eq(0).attr("checked","checked");
$("input[name='radio']").eq(1).removeAttr("checked");
$("input[name='radio']").eq(0).click();
});
$("#btn2").click(function(){
$("input[name='radio']").eq(0).removeAttr("checked");
$("input[name='radio']").eq(1).attr("checked","checked");
$("input[name='radio']").eq(1).click();
});
});
</script>
</body>
</html>
js前端radio问题
猜你喜欢
转载自jy-damon.iteye.com/blog/2296950
今日推荐
周排行