Ôö¼Ó javascript µÄ trim º¯Êý
È¥³ý×Ö·û´®×óÓÒÁ½¶ËµÄ¿Õ¸ñ£¬ÔÚvbscriptÀïÃæ¿ÉÒÔÇáËɵØÊ¹Óà trim¡¢ltrim »ò rtrim£¬µ«ÔÚjsÖÐȴûÓÐÕâ3¸öÄÚÖ÷½·¨£¬ÐèÒªÊÖ¹¤±àд¡£ÏÂÃæµÄʵÏÖ·½·¨ÊÇÓõ½ÁËÕýÔò±í´ïʽ£¬Ð§Âʲ»´í£¬²¢°ÑÕâÈý¸ö·½·¨¼ÓÈëString¶ÔÏóµÄÄÚÖ÷½·¨ÖÐÈ¥¡£
<input type="text" name="mytxt" value=" 12345678 " /><br>
<input type="button" name="cmd1" onclick="mytxt2.value=mytxt.value.trim()" value="È¥Á½±ßµÄ¿Õ¸ñ"/>
<input type="text" name="mytxt2"/><br>
<input type="button" name="cmd1" onclick="mytxt3.value=mytxt.value.ltrim()" value="È¥×ó±ßµÄ¿Õ¸ñ"/>
<input type="text" name="mytxt3"/><br>
<input type="button" name="cmd1" onclick="mytxt4.value=mytxt.value.rtrim()" value="È¥ÓұߵĿոñ"/>
<input type="text" name="mytxt4"/><br>
<script language="javascript">
String.prototype.trim=function(){
return this.replace(/(^s*)|(s*$)/g, "");
}
String.prototype.ltrim=function(){
return this.replace(/(^s*)/g,"");
}
String.prototype.rtrim=function(){
return this.replace(/(s*$)/g,"");
}
</script>
д³Éº¯Êý¿ÉÒÔÕâÑù£º
<script type="text/javascript">
function trim(str){ //ɾ³ý×óÓÒÁ½¶ËµÄ¿Õ¸ñ
return str.replace(/(^s*)|(s*$)/g, "");
}
function ltrim(str){ //ɾ³ý×ó±ßµÄ¿Õ¸ñ
return str.replace(/(^s*)/g,"");
}
function rtrim(str){ //ɾ³ýÓұߵĿոñ
return str.replace(/(s*$)/g,"");
}
</script>
Ïà¹ØÎĵµ£º
±¾ÎÄÖ÷ÒªÊdzöÓÚÓÐÅóÓÑʹÓÃÎÒÔÀ´Ð´µÄautocompleteµÄJS¿Ø¼þ¡£µ±Êý¾ÝÁ¿´óµÄʱºò£¬»á³öÏÖЧÂʼ«ÆäÂýµÄÇé¿ö£¬ÎÒÔÚÕâ¶Îʱ¼ä×ö³öµÄһЩ²âÊÔÒ²¼°Ò»Ð©¾Ñ飬Óë´ó¼Ò·ÖÏí£¬Èç¹ûÓдíµÄµØ·½£¬»¹ÇëÖ¸³ö¡£
¾¹ý²âÊÔ£¬ÎÒÃǻᷢÏÖÈçϵÄÇé¿ö»òÕß˵µÄ½áÂÛ£¬Èç¹ûÄúµÄ²âÊÔ½á¹ûÓëÎҵIJ»·û£¬Çë˵Ã÷ÔÒò£¬ÒÔ±ãÏ໥ѧϰ¡£
1£©µ±Ò»¸ö½Ï´óµÄHTML×Ö· ......
Dynamic Script Elements ¶¯Ì¬½Å±¾ÔªËØ
The Document Object Model (DOM) allows you to dynamically create almost any part of an HTML document using JavaScript. At its root, the <script> element isn't any different than any other element on a page: references can be retrie ......
XMLHttpRequest Script Injection XHR½Å±¾×¢Èë
Another approach to nonblocking scripts is to retrieve the JavaScript code using an XMLHttpRequest (XHR) object and then inject the script into the page. This technique involves creating an XHR object, downloading the JavaScript f ......
¾¼¸Ìì˼¿¼£¬Ïëµ½Ò»¸ö½Ð¡°ÎļþÓëÄ£¿é¡±µÄÎÊÌâ¡£ÎÒÃǵÄÄ£¿é¿Ï¶¨Ð´ÔÚÒ»¸öJSÎļþÖУ¬ÕâЩģ¿éÓÖ¿ÉÒÔ·ÖΪºËÐÄÄ£¿éÓëÍâΧģ¿é¡£ºËÐÄÄ£¿éµ±È»Ð´ÔÚÖ÷ÎļþÖУ¬ËüÓ¦¸Ã°üº¬×îÖØÒªµÄÂß¼£¬¼ÓÔØÆ÷£¬Áжӣ¬ÃüÃû¿Õ¼ä¹¹ÔìÆ÷µÈµÈ¡£µ«Èç¹ûÒ»¸öÎļþÖ»´æÔÚÒ»¸öÄ£¿éÕâҲ̫ÀË·ÑÁË£¬¶øÇһᵼÖÂÇëÇ󷨹ý¶à£¬Òò´Ë³öÏÖ¶à¸öÄ£¿é¡°¹²Éú¡±ÓÚÒ»¸öÎļþµÄÇé ......
1¡¢IsStartupScriptRegistered£º¶ÔÏóÊÇ·ñ×¢²áÁËÆôÓýű¾¡£
2¡¢IsClientScriptBlockRegistered£º¶ÔÏóÊÇ·ñ×¢²áÁ˿ͻ§¶Ë½Å±¾¿é¡£
3¡¢IsClientScriptIncludeRegistered£º¶ÔÏóÊÇ·ñ×¢²áÁ˿ͻ§¶Ë½Å±¾°üº¬¡£
µÚÒ»¸öÀý×Ó£º
string info = "<script>alert('ÄãºÃÂð£¿');</script>";
//ÅжÏʼþÊÇ·ñ±»×¢²á£¬Ð´ÈëÇ ......