« 全面分析IDC双线路实现技术方案Execute 方法 (ADO Connection) »

避免连续空格被提交


<script language="javascript">
<!--
function trim(str){
 var tempStr ="";
 for (i=0; i<str.length; i++){
   tempStr = tempStr + " ";
 }
 if (str == tempStr) {
   str = "";
 }
 return str;
}


function check(){
var len,str
str=trim(document.form.content.value)
len=str.length
if (len<1){ alert("无效查询条件!");document.form.content.focus(); return false;}
else return true;
}
-->
</script>


<form action="xxxxx" method="post" name="form" onsubmit="return check();">
<input type="text" name="content" value=""><br/>
<input type="submit" value="搜索">  
<input type="reset" value="重置" >
</form>

对于连续的半角空格可以在浏览器端屏蔽。
当然,作用不是很大
但是,如果输入一个空格不能提交,连续输入两个就可以,显得写代码的人比较菜,这个是用来吓唬那些不懂的人的。
原创文章如转载,请注明:转载自悠悠博客 [ http://www.ajaxstu.com/ ]

相关文章:

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。