Home > Web Front-end > JS Tutorial > Solve the problem of radio reselection implemented by jquery_jquery

Solve the problem of radio reselection implemented by jquery_jquery

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

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

Copy after login

(Note: The jquery version used is 1.10.2.)

Use jquery's removeAttr() to clear the checked attribute of radio. Use attr('checked',true) to attach the checked attribute to the corresponding radio. But when the page is displayed, it is not selected.

Solution:

Implemented using native js code.

  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

Testing is OK. It can be selected and the page can be displayed correctly.

The above is the entire content of this article, I hope you all like it.

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