//判断输入内容是否为空
function isNull(id,err_info) {
var str = document.getElementById(id).value.trim();
if (str.length == 0) {
alert(err_info);
return true;
}else{
return false;
}
}
function isNull(id,err_info) {
var str = document.getElementById(id).value.trim();
if (str.length == 0) {
alert(err_info);
return true;
}else{
return false;
}
}
<script type='text/javascript'>
String.prototype.trim = function(){
return this.replace(/^\s+|\s+$/g,'');
}
function isNull(id,err_info) { var str = document.getElementById(id).value.trim(); if (str.length == 0) {
alert(err_info);
return true;
}else{
alert("|"+str+"|")
return false;
}}
</script>
<input type='text' value=' ' id='hehe' onclick="isNull('hehe','what the fuck!?')">
function isNull(id,err_info) { var str = document.getElementById(id).value;
str = str.replace(/(^\s+)|(\s+$)/g,"");
if (str.length == 0) {
alert(err_info);
return false;
}else{
return true;
} }
呵呵!!!强人啊!!!!
代码貌似没有问题。