日期:2014-05-17 浏览次数:20653 次
<html> <script language="javascript" defer="defer"> var cur; function check(){ var val; var rds = document.forms[0].rd; for(var i=0;i<rds.length;i++){ if(rds[i].checked){ val = i; break; } } if(val != cur){cur = val; alert("changed")} } window.onload=function(){ var rds = document.forms[0].rd; for(var i=0;i<rds.length;i++){ if(rds[i].checked){ cur = i; break; } } } </script> <body> <form> <input type="radio" name="rd" value="0" checked="checked" onclick="check()"> 0<br> <input type="radio" name="rd" value="1" onclick="check()"> 1<br> <input type="radio" name="rd" value="2" onclick="check()"> 2<br> </form> </body> </html>
------解决方案--------------------
<div id=radios> a <input type=radio name=a value=a > b <input type=radio name=a value=b> c <input type=radio name=a value=c> </div> <script language="javascript"> <!-- var obj=document.getElementById("radios").getElementsByTagName("input") for (var i=0;i<obj.length;i++){ (function(k){obj[i].onclick=function(){cha(k)}})(i) } var lastChecked=null function cha(k){ if (lastChecked==k)return if (lastChecked!=null){ //处理obj[lastChecked] alert("上次选中:"+lastChecked) } lastChecked=k //处理obj[lastChecked] alert("本次选中:"+lastChecked) } //--> </script>
------解决方案--------------------
失去选中,也即失去焦点,那么失去焦点的事件可以在对象中这样响应
...onblur="javascript:workFunName(参数);"...
------解决方案--------------------
做了个测试
<!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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> </head> <body> <form method="post" action=""> <input type="radio" name="ask1" id="a1" value="v1" />a1 <input type="radio" name="ask1" id="a2" value="v2" />a2 <input type="radio" name="ask1" id="a3" value="v3" />a3 </form> </body> <script type="text/javascript"> //<![CDATA[ function a1(){ alert('a1 .... do something'); } function a2(){ alert('a2 .... do something'); } function a3(){ alert('a3 .... do something '); } function setradio(oname, v, fn){ var rdos = document.getElementsByName(oname); for ( var i=0,