初学javascipt 请问怎么动态传入控件名?
请看 checkNum(form1.num1) 函数
<%@ page contentType="text/html;charset=gb2312"%><html><head><script language="javascript">function checkNum(this){ if(this.value=="") { window.alert("空"); } }</script></head><body><form name="form1" action="myresult.jsp" ><input type="text" name="numl"><br><select name="flag"><option value=+>+</option><option value=->-</option><option value=*>*</option><option value=/>/</option></select><br><input type="text" name="num2"><br><input type="submit" onclick="checkNum(form1.num1)" value="计算"></form></body></html>
<html><head><script language="javascript">function checkNum(o)//不能用this关键字{ if(o.value=="") { window.alert("空"); } alert(o.value);}</script></head><body><form name="form1" action="myresult.jsp" ><input type="text" name="num1"><br>num1拼写错误<select name="flag"><option value=+>+</option><option value=->-</option><option value=*>*</option><option value=/>/</option></select><br><input type="text" name="num2"><br><input type="submit" onclick="checkNum(form1.num1)" value="计算"></form></body></html>