解决jquery实现的radio重新选中的问题

<div class="jb51code">
<pre class="brush:xhtml;">
<input type="radio" name="test"/>

<input type="radio" name="test" id = "input2"/>

(说明:使用的jquery 版本是 1.10.2。)

使用 jquery 的removeAttr(),清除掉 radio 的checked属性后。使用 attr('checked',true)可以给对应的radio 附上 checked属性。但是页面展示,却没有选中。

解决方法

  使用原生js 代码实现。

rush:js;">   var inputList = document.getElementByName("test");

  for(var x=0;x<inputList.length;x++){

    inputList.checked=false; //取消选中

  }

  var input = document.getElementById("input2");

  input.checked = true; //选中第二个  

测试是可以的。能选中,且页面显示正确。

以上所述就是本文的全部内容,希望大家能够喜欢。

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...