<script type="text/javascript">
function addUser() {
var userIdField = document.getElementById("userId");
if (trim(userIdField.value) == "" ) {
alert("用户代码不能为空!");
return;
}
}
</script> <form name="form1" method="POST" action="--WEBBOT-SELF--"> <input name=userId type="text" id="userId">
<input type="button" value="添加" onClick="addUser()">
</form>
function addUser() {
var userIdField = document.getElementById("userId");
if (trim(userIdField.value) == "" ) {
alert("用户代码不能为空!");
return;
}
}
</script> <form name="form1" method="POST" action="--WEBBOT-SELF--"> <input name=userId type="text" id="userId">
<input type="button" value="添加" onClick="addUser()">
</form>
if (!(/\S+/).test(userIdField.value)) {
alert("用户代码不能为空!");
return;
}
String.prototype.trim = function() {
return this.replace(/^\s*/,"").replace(/\s*$/,"");
}//注册了之后以后字符串都可以用trim了var i = " asdf ";
alert(i.trim().length);
String.prototype.trim = function() {
return this.replace(/(?:^\s+)|(?:\s+$)/g,'');
}alert('1'+(' xxxx '.trim())+'2');