在页面需要验证文本框时,往往需要数据的传递,form表单中的传递方法有button和form.submit两种
<form id="formid" name= "myform" method = 'post' action = 'login.jsp' >
method为传递的格式,post get 。
login.jsp是处理这个表单提交的目标地址。 method是表示username和password这两个参数用什么方式传递到login,一般有get,post,put等。
js代码:
function Mycheck2(){ if(form1.text1.value==""){ alert("请输入表单的内容!!!"); form1.text1.focus(); return ; } form1.submit(); }jsp:
<form name="form1" method="post" action="?formid=1">
表单一:
<input name="text1" type="text" class=text value="text1">
<input type="button" name="submit1" value="提交" οnclick="Mycheck();">
</form>
即点击button,会触发form1.submit();