日期:2014-05-16 浏览次数:20380 次
<input type="radio" name="error" value="yes" checked="checked"/>有 <input type="radio" name="error" value="no" />无
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script src="http://code.jquery.com/jquery-latest.js"></script> <script> $(document).ready(function () { $('input[type=radio]').click(function () { alert($(this).val()); }); }) </script> </head> <body> <input type="radio" name="error" value="yes" checked="checked"/>有 <input type="radio" name="error" value="no" />无 </body> </html>
------解决方案--------------------
<input type="radio" name="error" value="yes" checked="checked"/>有 <input type="radio" name="error" value="no" />无 <input type="button" value="点击我" onclick="getValue()" /> <script> function getValue(){ var es=document.getElementsByName('error'); var v=0; for(var i=0;i<es.length;i++){ if(es[i].checked){ v=es[i].value; break; } } alert(v); } </script>
------解决方案--------------------
<script type="text/javascript"> var New=document.getElementsByName("error"); var strNew; for(var i=0;i<New.length;i++) { if(New.item(i).checked){ strNew=New.item(i).getAttribute("value"); break; } else{ continue; } } </script>