Javascript ÕýÔò±í´ïʽʹÓÃÊÖ²á
Javascript ÕýÔò±í´ïʽʹÓÃÊÖ²á
Javascript 2008-10-30 10:15 ÔĶÁ97 ÆÀÂÛ0
×ֺţº ´ó´ó ÖÐÖРСС
Ò»£®ÕýÔò±í´ïʽƥÅä³£ÓÃÓï·¨
“+”×Ö·û£º¹æ¶¨±í´ïʽ×Ö·û³öÏÖÒ»´Î»ò¶à´Î¡£
“*”×Ö·û£º¹æ¶¨±í´ïʽ×Ö·û³öÏÖÁã´Î»ò¶à´Î¡£
“?”×Ö·û£º¹æ¶¨±í´ïʽ×Ö·û³öÏÖÁã´Î»òÒ»´Î¡£
^ Æ¥ÅäµÄÊÇ×Ö·ûµÄ¿ªÍ· ,Æ¥ÅäµÄÊÇÒ»ÐеĿªÍ·
$ Æ¥ÅäµÄÊÇ×Ö·ûµÄ½áβ ,Æ¥ÅäµÄÊÇÒ»ÐеĽáβ
\b Æ¥ÅäµÄÊÇÒ»¸ö´ÊÓïµÄ±ß½ç.¼ò¶øÑÔÖ®¾ÍÊÇλÓÚ×Ö·û\w ºÍ \wÖ®¼äµÄλÖÃ(×¢Òâ:[\b]Æ¥ÅäµÄÊÇÍ˸ñ·û)
\B Æ¥ÅäµÄÊÇ·Ç´ÊÓïµÄ±ß½çµÄ×Ö·û
[A-Z]¡¡Æ¥Åä´ÓAµ½Z·¶Î§ÄÚÈκÎÒ»¸ö´óд×Öĸ¡£
[a-z]¡¡ Æ¥Åä´Óaµ½z·¶Î§ÄÚÈκÎÒ»¸öСд×Öĸ¡£
[0-9]/¡¡Æ¥Åä´Ó0µ½9·¶Î§ÄÚÈκÎÒ»¸öÊý×Ö¡£
([a-z][A-Z][0-9])+¡¡ Æ¥ÅäÈκÎÓÉ×ÖĸºÍÊý×Ö×é³ÉµÄ×Ö·û´®£¬Èç “aB0” µÈ¡£
\d Æ¥ÅäÒ»¸öÊý×Ö×Ö·û¡£µÈ¼ÛÓÚ [0-9]
\D Æ¥ÅäÒ»¸ö·ÇÊý×Ö×Ö·û¡£µÈ¼ÛÓÚ [^0-9]
\f Æ¥ÅäÒ»¸ö»»Ò³·û¡£µÈ¼ÛÓÚ \x0c ºÍ \cL
\n Æ¥ÅäÒ»¸ö»»Ðзû¡£µÈ¼ÛÓÚ \x0a ºÍ \cJ
\r Æ¥ÅäÒ»¸ö»Ø³µ·û¡£µÈ¼ÛÓÚ \x0d ºÍ \cM
\s Æ¥ÅäÈκοհ××Ö·û£¬°üÀ¨¿Õ¸ñ¡¢ÖƱí·û¡¢»»Ò³·ûµÈµÈ,µÈ¼ÛÓÚ [ \f\n\r\t\v]
\S£ºÓÃÓÚÆ¥Åä³ýµ¥¸ö¿Õ¸ñ·ûÖ®ÍâµÄËùÓÐ×Ö·û£»
\w Æ¥Åä°üÀ¨Ï»®ÏßµÄÈκε¥´Ê×Ö·û,µÈ¼Û[A-Za-z0-9_]
\W Æ¥ÅäÈκηǵ¥´Ê×Ö·û,µÈ¼ÛÓÚ [^A-Za-z0-9_]
¶þ£®×Ö·û´®µÄJavascript ÕýÔò±í´ïʽ´¦Àí
(1)´´½¨regular expressionÓÐÁ½ÖÖ·½·¨£¬Ò»ÖÖÊÇÖ±½ÓʹÓÃ×Ö·û´®¶¨Òå;ÁíÒ»ÖÖÊÇʹÓÃReqExp¹¹Ô캯Êý´´½¨¡£
Óï·¨ 1: re = /pattern/[flags]
Óï·¨ 2 ;re = new RegExp("pattern",["flags"])
Èç¹ûʹÓÃÓï·¨ 1£¬Óà "/" ×Ö·û·Ö¸ôģʽ¡£
Èç¹ûÓÃÓï·¨ 2£¬ÓÃÒýºÅ½«Ä£Ê½ÒýÆðÀ´£»Èçnew RegExp("hello","g");
Flags¿ÉÑ¡Ïî,¿ÉÒÔÓÃÒÔϲÎÊý£º
g £¨È«ÎIJéÕÒ³öÏÖµÄËùÓÐ pattern£©
i £¨ºöÂÔ´óСд£©
m £¨¶àÐвéÕÒ£©
ÀýÈ磺
·½·¨1£º var pattern = /sS/;
·½·¨2£º var pattern = new RegExp("sS");
var zipcode=new ReqExp("\\d{5}","g"); //µÚÒ»¸ö±äÁ¿ÊÇÕýÔò±í´ïʽ(/ / ÀïµÄ)£¬µÚ¶þ¸öÊÇÓÃ//À´¼Ói»ògµÄ¡£ºöÂË´óСд²¢ËÑË÷
(2£©String¶ÔÏó³£Ó÷½·¨
search·½·¨¡£
“JavaScript”.search(/script/i/);//Õâ¸ö·½·¨·µ»ØÖµÊÇ4£¬Ò²¾ÍÊÇjavascriptµÚÎå¸ö×Öĸ¡£¿ªÊ¼ÖµÊÇ0£¬ËùÒÔÊÇ4¡£
Ïà¹ØÎĵµ£º
Ò»¡¢ÀàÐÍת»»µÄ·½·¨ºÍÓ¦¸Ã×¢ÒâµÄÎÊÌ⣺
1£¬×ª»»Îª²¼¶ûÐÍ£º
£¨1£©ÓÃÁ½´Î·ÇÔËËã(!):
!!5 ==> true
£¨2£©Óò¼¶ûÐ͵Ĺ¹Ô캯Êý£º
new Boolean(5) == > true
ֵת»»Îª²¼¶ûÀàÐÍΪfalse£º
0£¬+0£¬-0£¬NaN£¬""(¿Õ×Ö·û´®),undefined,null
³ýÉÏÃæµÄÖµÆäËûÖµÔÚת»»ÒÔºóΪtrue£¬ÐèÒªÌرðÌáµ½µÄÊÇ:
"0",new Object(),funct ......
Ò»¡¢ÔÚHTMLÖÐǶÈëJavasriptµÄ·½·¨
Ö±½ÓÔÚJavascript´úÂë·ÅÔÚ±ê¼Ç¶Ô<script>ºÍ</script>Ö®¼ä
ÓÉ<script />±ê¼ÇµÄsrcÊôÐÔÖƶ¨ÍⲿµÄjsÎļþ
·ÅÔÚʼþ´¦Àí³ÌÐòÖУ¬±ÈÈ磺<p onclick="alert('ÎÒÊÇÓÉonclickʼþÖ´ÐеÄJavascript')">µã»÷ÎÒ</p>
×÷ΪURLµÄÖ÷Ì壬Õâ¸öURLʹÓÃÌØÊâµÄJavascript ......
ÕâÈý¸öÓïÑÔ·Ö±ðÊÇÈý¸ö¹«Ë¾¿ª·¢µÄ£¬SUNµÄJava£¬NetscapeµÄJavaScript£¬MicrosoftµÄJScript
JavaScriptÊÇÓÉNetscape¹«Ë¾¿ª·¢²¢ËæNavigatorµ¼º½ÕßÒ»Æð·¢²¼µÄ¡¢½éÓÚJavaÓëHTMLÖ®¼ä¡¢»ùÓÚ¶ÔÏóʼþÇý¶¯µÄ±à³ÌÓïÑÔ£¬²»ÐèÒªJava±àÒëÆ÷£¬¶øÊÇÖ±½ÓÔËÐÐÔÚWebä¯ÀÀÆ÷ÖУ¬ËüµÄÇ°ÉíÊÇLive Script¡£
JScriptÊÇÒ»ÖÖÀàËÆJavaScriptµÄÓïÑÔ¡ ......
˼·£ºä¯ÀÀͼƬ£¬¶ÁÈ¡Æä¿í¶ÈImageW£¬¸ß¶ÈÖµImageH¡£¶ÁÈ¡Óû§ÊäÈëµÄ·Ö³É¼¸ÐÐRow¼¸ÁÐCol¡£
ÿ¸ö·½¿é£ºboxW=ImageW/Col£»boxH=ImageH/Row£»
ÔÚ1µ½Row*ColÖÐËæ»ú£¬µÚi¸öͼƬµÄλÖÃÉèΪpos¡¾i¡¿¡£È»ºó¶¯Ì¬´´½¨divÉú³ÉRow* ......
¶ÁÈ¡XMLÎĵµ£»
²ÉÓõݹéÉú³ÉÎÞÏÞ¼¶µÄÊ÷Ðβ˵¥£»
Äܹ»ÏìÓ¦Êó±êʼþ£¬Õ¹¿ªÓë²ðµþ×Ó¼¶²Ëµ¥£»
Ê×ÏÈÊÇÉú³ÉÒ»¸öXMLÎĵµ£¬ÎÒÓõÄÊÇXML SpyµÄ±à¼Æ÷£»
<?xml version="1.0" encoding="utf-8"?>
<menu>
<menu name="Ã÷ ......