日期:2014-05-16  浏览次数:20367 次

jQuery radio 先删除checked属性,在选中,获取不到选中的值??在线等
本帖最后由 kll329582600 于 2013-08-30 15:04:33 编辑
<input name="rdogroup" type="radio" value="1" />男
<input name="rdogroup" type="radio" value="0" />女
<input type="button" value="button" />
<script type="text/javascript">

    $("input:button").click(function () {
        $("input").filter(":radio").removeAttr("checked");
        //先删除checked属性(设置checked为false结果一样),在点击选中一个
        alert($("input").filter(":radio:checked").val()); //结果是undefined
        //求解,我事先要先清空
    });

</script>
jQuery

------解决方案--------------------
每次点机button,都删除了checked,它能取到值才怪呢
------解决方案--------------------

jQuery(function(){
    $("input").filter(":radio").removeAttr("checked");
    $("input:button").click(function () {
        //$("input").filter(":radio").removeAttr("checked");
        //先删除checked属性(设置checked为false结果一样),在点击选中一个
        alert($(":radio:checked").val()); //结果是undefined
        //求解,我事先要先清空
    });
});

------解决方案--------------------
 $("input").filter(":radio").removeAttr("checked"); 放到外面 写成
$(function(){
 $("input").filter(":radio").removeAttr("checked");
})
------解决方案--------------------
 你这个 $("input").filter(":radio:checked")  已经过滤不出来了。 也就找不到了。你再 val 当然是undefined
------解决方案--------------------
 
$("input:button").click(function () {