【发布时间】:2015-10-22 10:02:01
【问题描述】:
我是 Javascript 和 jQuery 的新手。我得到的只是这个 JS 函数来验证我的表单。我在这两种形式中都有一些共同的领域。而不是调用不同的函数来验证不同的表单,我想要一个 JS 函数来验证两种表单中的所有公共字段。仅供参考,这两种形式都在不同的页面中。
JS
function check1(){
var x = document.forms["form1"]["type"].value;
if (x == null || x == "") {
alert("Please Enter Type");
return false;
}
function check2(){
var x = document.forms["form2"]["type"].value;
if (x == null || x == "") {
alert("Please Enter Type");
return false;
}
HTML
form1
<form name="form1" method="post" action="#" onsubmit="return check1()">
<input type="text" name="type" id="type">
</form>
form2
<form name="form2" method="post" action="#" onsubmit="return check2()">
<inout type="text" name="type" id="type">
</form>
提前致谢。请容忍我,我是新手。
【问题讨论】:
标签: javascript jquery html forms validation