初学PHP,下面是实现文本框内容随下拉框变化的代码实现:
<!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> <script language="javascript"> function look(){ var se =document.getElementById("sel"); var option=se.getElementsByTagName("option"); var str = "" ; for(var i=0;i<option.length;++i) { if(option[i].selected) { document.getElementById("test").value = option[i].text; } } } </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> </body> </html>
时间: 2024-10-27 07:51:04