【发布时间】:2014-03-15 08:13:07
【问题描述】:
我在 jsp 页面上有多个文本框。我想在提交时检查每个文本框是否为空。当我提交时,如果任何文本框为空,则不应允许提交到 servlet 页面。如何检查多个文本框?
<script type="text/javascript">
function checkvalue() {
var mystring = document.getElementById('uname').value;
var mystring1 = document.getElementById('pass').value;
if(!mystring.match(/\S/) && !mystring1.match(/\S/))
{
alert ('Empty value is not allowed');
return false;
}
else
{
alert("correct input");
return true;
}
}
我已经尝试了上面的javascript。我只想知道如何减少多个文本框的代码?
【问题讨论】:
-
到目前为止你尝试了什么?
-
Duplicate, find answer here 在这里,你会找到完整的解释。