$.trim(str)
jQuery內(nèi)部實(shí)現(xiàn)為:
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>以上所述是小編給大家介紹的JS去掉字符串前后空格、阻止表單提交的實(shí)現(xiàn)代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對武林網(wǎng)網(wǎng)站的支持!
新聞熱點(diǎn)
疑難解答