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

Solve the problem of radio reselection implemented by jquery_jquery

WBOY
WBOYOriginal
2016-05-16 15:51:411198browse
<input type="radio" name="test"/>

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

(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; //选中第二个  

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.

Statement:
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