$.trim(str)
jQuery内部实现为:
function trim(str){  
  return str.replace(/^(\s|\u00A0)+/,'').replace(/(\s|\u00A0)+$/,'');  
}

使用JS和JQuery 阻止表单提交的两种方法

<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gbk"> 
<title>JavaScript禁止提交表单</title> 
<script type="text/javascript"> 
function getObj(id){ 
  var Obj = document.getElementById(id).value; 
  return Obj; 
} 
function check(){ 
  if(getObj("test")==""){ 
    alert("文本框输入为空,不能提交表单!"); 
    document.getElementById("test").focus; 
    return false;//false:阻止提交表单 
  } 
} 
</script> 
</head> 
<body> 
<form action="index.htm" method="post" onsubmit="return check()"> 
  <input type="text" name="test" id="test"> 
  <input type="submit" value="提交"> 
</form> 
</body> 
</html>


相关评论(0)
您是不是忘了说点什么?

友情提示:垃圾评论一律封号...

还没有评论,快来抢沙发吧!