1 javascript ÕýÔò
¶ÔÏó´´½¨ ºÍÓ÷¨
ÉùÃ÷javascript ÕýÔò
±í´ïʽ
¸´ÖÆ´úÂë
´úÂëÈçÏÂ:
var reCat = new RegExp("cat");
ÄãÒ²¿ÉÒÔ
var reCat = /cat/; //Perl ·ç¸ñ £¨ÍƼö£©
2 ѧϰ×î³£ÓÃµÄ test exec match search replace split 6¸ö·½·¨
1£© test ¼ì²éÖ¸¶¨µÄ×Ö·û´®ÊÇ·ñ´æÔÚ
¸´ÖÆ´úÂë
´úÂëÈçÏÂ:
var data = "123123";
var reCat = /123/gi;
alert(reCat.test(data)); //true
//¼ì²é×Ö·ûÊÇ·ñ´æÔÚ g ¼ÌÐøÍùÏÂ×ß i ²»Çø·Ö´óСд
2£© exec ·µ»Ø²éѯֵ
¸´ÖÆ´úÂë
´úÂëÈçÏÂ:
var data = "123123,213,12312,312,3,Cat,cat,dsfsdfs,";
var reCat = /cat/i;
alert(reCat.exec(data)); //Cat
3£©match µÃµ½²éѯÊý×é
¸´ÖÆ´úÂë
´úÂëÈçÏÂ:
var data = "123123,213,12312,312,3,Cat,cat,dsfsdfs,";
var reCat = /cat/gi;
var arrMactches = data.match(reCat)
for (var i=0;i < arrMactches.length ; i++)
{
alert(arrMactches[i]); //Cat cat
}
4£© search ·µ»ØËÑË÷λÖà ÀàËÆÓÚindexof
¸´ÖÆ´úÂë
´úÂëÈçÏÂ:
var data = "123123,213,12312,312,3,Cat,cat,dsfsdfs,";
var reCat = /cat/gi;
alert(data.search(reCat)); //23
5£© replace Ìæ»»×Ö·û ÀûÓÃÕýÔò
Ìæ»»
¸´ÖÆ´úÂë
´úÂëÈçÏÂ:
var data = "123123,213,12312,312,3,Cat,cat,dsfsdfs,";
var reCat = /cat/gi;
alert(data.replace(reCat,"libinqq"));
6£©split ÀûÓÃÕýÔò
·Ö¸îÊý×é
¸´ÖÆ´úÂë
´úÂëÈçÏÂ:
var data = "123123,213,12312,312,3,Cat,cat,dsfsdfs,";
var reCat = /\,/;
var arrdata = data.split(reCat);
for (var i = 0; i < arrdata.length; i++)
{
alert(arrdata[i]);
}
3 ѧϰÏ ¼òµ¥Àà ¸ºÏòÀà ·¶Î§Àà ×éºÏÀà
¸´ÖÆ´úÂë
´úÂëÈçÏÂ:
//¼òµ¥Àà
var data = "1libinqq,2libinqq,3libinqq,4libinqq";
var reCat = /[123]libinqq/gi;
var arrdata = data.match(reCat);
for (var i = 0; i < arrdata.length; i++)
{
alert(arrdata[i]); // 1libinqq 2libinqq 3libinqq
}
//¸ºÏòÀà
var data = "alibinqq,1libinqq,2libinqq,3libinqq,4libinqq"; //\u0062cf
var reCat = /[^a123]libinqq/gi;
var arrdata = data.matc
ÔÚ×öÒ»¸öÏîÄ¿ÖУ¬½Ó´¥µ½ÁËJavaScript£¬Ö÷ÒªÊǵã»÷Ò»¸ö²éѯ°´Å¥È»ºóµ¯³öÒ»¸öÍøÒ³¶Ô»°¿ò£¬µ±ÔÚ¶Ô»°¿òÖÐÊäÈë²éѯÌõ¼þ£¬µã»÷È·¶¨ºóÓÖ·µ»Øµ½ÔÀ´Ò³Ãæ,µÃ³ö²éѯ½á¹û¡£
Ò³ÃæÈçͼ£º
ÔÚǰ̨¼ÓÁËÒ»¸öÒþ²ØµÄDIV£¬ÀïÃæ·ÅÈëÁ½¸ö¿Ø¼þ¡£ÈçÏ£º
<div style="display:none">
< ......
ÎÒÃǶ¼ÖªµÀ£¬ajaxÄÜÌá¸ßÒ³ÃæÔØÈëµÄËٶȵÄÖ÷ÒªÔÒòÊÇͨ¹ýajax¼õÉÙÁËÖظ´Êý¾ÝµÄÔØÈ룬ÕæÕý×öµ½°´Ðè»ñÈ¡£¬¼ÈÈ»Èç´Ë£¬ÎÒÃÇÔÚдajax³ÌÐòµÄʱºò²»·ÁËÍ·ðË͵½Î÷£¬ÔÚ¿Í»§¶ËÔÙ×öÒ»´Î»º´æ,½øÒ»²½Ìá¸ßÊý¾ÝÔØÈëËٶȡ£ÄǾÍÊÇÔÚÔØÈëÊý¾ÝµÄͬʱ½«Êý¾Ý»º´æÔÚä¯ÀÀÆ÷ÄÚ´æÖУ¬Ò»µ©Êý¾Ý±»ÔØÈ룬ֻҪҳÃæδˢУ¬¸ÃÊý¾Ý¾ÍÓÀÔ¶µÄ»º´æÔÚÄÚ´æÖУ¬µ±Ó ......
JSON £¨JavaScript Object Notation£©Ò»ÖÖ¼òµ¥µÄÊý¾Ý¸ñʽ£¬±Èxml¸üÇáÇÉ¡£ JSON ÊÇ JavaScript ÔÉú¸ñʽ£¬ÕâÒâζ×ÅÔÚ JavaScript Öд¦Àí JSON Êý¾Ý²»ÐèÒªÈκÎÌØÊâµÄ API »ò¹¤¾ß°ü¡£
JSONµÄ¹æÔòºÜ¼òµ¥£º ¶ÔÏóÊÇÒ»¸öÎÞÐòµÄ“‘Ãû³Æ/Öµ’¶Ô”¼¯ºÏ¡£Ò»¸ö¶ÔÏóÒÔ“{”£¨×óÀ¨ºÅ£©¿ªÊ¼£¬“}&rdq ......