JS Get Radio Value
The code is as follows |
Copy Code |
<script language= "JavaScript" > function Validateadd () { var new=document.getelementsbyname ("bmfw_id"); var strnew; for (Var i=0;i<new.length;i++) { if (New.item (i). Checked) { Strnew=new.item (i). getattribute ("value"); Break }else{ Continue } } if (strnew== "no") { Alert ("ok! "); return false; } } </script> |
jquery gets radio value simple
jquery gets radio value simple
To get a radio value there are several ways to give the code directly:
$ (' input[name= ' Testradio ']:checked '). Val ();
$ (' input:radio:checked '). Val ();
$ (' input[@name = ' testradio '][checked] ');
$ (' input[name= "Testradio"]). Filter (': Checked ');
Cases
The code is as follows |
Copy Code |
<script type= "Text/javascript" Src= "Https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js" ></script> <script Type= "Text/javascript" > $ (function () { $ (' #go '). Click (function () { var radio = $ (' input[name= ' testradio '] '). Filter (': Checked '); if (radio.length) Alert (Radio.val ()); Else Alert (' Please select a radio ');
}); $ (' #go2 '). Click (function () { $ (' input[name= ' testradio '] '). each (function () { alert (this.value); }); }) $ (' #go3 '). Click (function () { Alert ($ (' input[name= "Testradio"]:eq (1) '). Val ()); }) }) </script> <body> <input type= "Radio" name= "Testradio" value= "jquery gets radio value" />jquery get Radio value <BR/ > <input type= "Radio" name= "Testradio" value= "jquery Gets the value of the checkbox"/>jquery get the value of the checkbox <br/ > <input type= "Radio" name= "Testradio" value= "jquery Gets the value of a select" />jquery gets the value of the Select <br/> & Lt;button id= "Go" > Selected radio value </button> <button id= "Go2" > Traverse all Radio values </button> < Button id= "Go3" > take the value of the second radio </button> </body> |