Use js to get the selected value of the radio, which is often used on the submission page. At the same time, it also introduces how to get the value of the radio without selecting it.
Example,
<script> </li>
<li>var chk = 0; </li>
<li>window.onload=function (){ </li>
<li>var chkObjs = document.getElementsByName("radio"); </li>
<li>for(var i=0;i<chkObjs .length;i++){ <li>if(chkObjs[i].checked){ <li>chk = i; <li>break; <li>} <li>} <li>} <li>function check_radio(){ <li>var chkObjs = document.getElementsByName("radio"); <li>for(var i=0;i<chkObjs.length;i++){ <li>if(chkObjs[i].checked){ <li>if(chk == i){ <li>alert("The radio value has not changed and cannot be submitted"); <li>break; <li>} <li>} <li>} <li>} <li></script>
一;
two;
three;
four;
五;
Get the value of radio without making a choice
JPY
Euro< ;/p>
Copy code
Native JS method: (Native DOM operations will treat text as a node, so there will be nextSibling)
var dollar = document.getElementsByName("money")[0].nextSibling.nodeValue;
var yen = document.getElementsByName("money")[1].nextSibling.nodeValue;
var euro= document.getElementsByName("money")[2].nextSibling.nodeValue;
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