Home > Web Front-end > JS Tutorial > body text

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

WBOY
Release: 2016-05-16 15:51:41
Original
1137 people have browsed it
<input type="radio" name="test"/>

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

Copy after login

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

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

解决方法:

  使用原生js 代码实现。

  var inputList = document.getElementByName("test");

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

    inputList[x].checked=false; //取消选中

  }

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

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

Copy after login

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

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!