这久在修改一个项目的小东西,要求把下拉框改为单选框,由于代码封闭,修改不了获取函数,所以想了个办法让下拉框的内容随单选框的内容变化,下面把代码分享给大家:
<!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>PHP下拉框对单选框变化</title> <script type="text/javascript"> var m = "5"; document.getElementById("test").value= m; </script> </head> <body> <input type="text" name="test" id="test"> <select name="sel" id="sel" onchange="look();"> <option value="1" >11</option> <option value="2" selected>22</option> <option value="3">33</option> </select> <INPUT TYPE="radio" NAME="a" value="1" onclick="check();">aaaaaaaaaa<br> <INPUT TYPE="radio" NAME="a" value="2" onclick="check();">bbbbbbbbb<br> <INPUT TYPE="radio" NAME="a" value="3" onclick="check();">cccc<br> <script LANGUAGE="javascript"> <!-- function check() { var sel = 0; for (var i = 0; i < document.getElementsByName("a").length; i++) { if(document.getElementsByName("a")[i].checked) { sel = document.getElementsByName("a")[i].value; } } var m = sel; for(var i = 0;i<document.getElementById("sel").length;i++) { with(document.getElementById("sel").options[i]) { if(value == m) { selected = true; } } } alert(sel); } //--> </script> <script type="text/javascript"> </script> </body> </html>