JavaScriptÖеÄ×Ö·û´®²Ù×÷
Ò»¡¢¸ÅÊö
×Ö·û´®ÔÚJavaScriptÖм¸ºõÎÞ´¦²»ÔÚ£¬ÔÚÄã´¦ÀíÓû§µÄÊäÈëÊý¾ÝµÄʱºò£¬ÔÚ¶ÁÈ¡»òÉèÖÃDOM¶ÔÏóµÄÊôÐÔʱ£¬ÔÚ²Ù×÷cookieʱ£¬µ±È»»¹Óиü¶à...¡£JavaScriptµÄºËÐIJ¿·ÖÌṩÁËÒ»×éÊôÐԺͷ½·¨ÓÃÓÚͨÓõÄ×Ö·û´®²Ù×÷£¬Èç·Ö¸î×Ö·û´®£¬¸Ä±ä×Ö·û´®µÄ´óСд£¬²Ù×÷×Ó×Ö·û´®µÈ¡£
µ±Ç°µÄ´ó²¿·Öä¯ÀÀÆ÷Ò²ÄÜ´ÓÇ¿´óµÄÕýÔò±í´ïʽ»ñÒ棬ÒòΪËü¼«´óµØ¼ò»¯ÁË´óÁ¿µÄ×Ö·û´®²Ù×÷ÈÎÎñ£¬²»¹ýËüÒ²ÐèÒªÄã¿Ë·þÒ»ÌõÓÐЩ¶¸Ç͵ÄѧϰÇúÏß¡£ÔÚÕâÀÖ÷ÒªÊǽéÉÜ×Ö·û´®±¾ÉíµÄһЩ²Ù×÷£¬ÕýÔò±í´ïʽ»áÔÚÒÔºóµÄËæ±ÊÖÐÉæ¼°¡£
¶þ¡¢×Ö·û´®µÄ´´½¨
´´½¨Ò»¸ö×Ö·û´®Óм¸ÖÖ·½·¨¡£×î¼òµ¥µÄÊÇÓÃÒýºÅ½«Ò»×é×Ö·û°üº¬ÆðÀ´£¬¿ÉÒÔ½«Æ丳ֵ¸øÒ»¸ö×Ö·û´®±äÁ¿¡£
var myStr = "Hello, String!";
¿ÉÒÔÓÃË«ÒýºÅ»òµ¥ÒýºÅ½«×Ö·û´®°üº¬£¬µ«Òª×¢Ò⣬×÷Ϊ½ç¶¨×Ö·û´®µÄÒ»¶ÔÒýºÅ±ØÐëÊÇÏàͬµÄ£¬²»ÄÜ»ìÓá£
Ïñvar myString = "Fluffy is a pretty cat.'; ÕâÑùµÄÉùÃ÷¾ÍÊÇ·Ç·¨µÄ¡£
ÔÊÐíʹÓÃÁ½ÖÖÒýºÅ£¬Ê¹µÃijЩ²Ù×÷±äµÃ¼òµ¥£¬±ÈÈ罫һÖÖǶÈëÁíÍâÒ»ÖÖ£º
document.write("<img src='img/logo.jpg' height='30' width='100' alt='Logo'>");
ÎÒÃÇÔÚÉÏÃæ½Å±¾´´½¨Á˼¸¸ö×Ö·û´®£¬µ«±¾ÖÊÉÏ£¬ËüÃDz¢²»ÊÇÕæÕýµÄ×Ö·û´®¶ÔÏó£¬×¼È·µØ˵£¬ËüÃÇÊÇ×Ö·û´®ÀàÐ͵ÄÖµ¡£Òª´´½¨Ò»¸ö×Ö·û´®¶ÔÏ󣬿ÉʹÓÃÈçÏÂÓï¾ä£ºvar strObj = new String("Hello, String!");
ʹÓÃtypeofÔËËã·û²é¿´»á·¢ÏÖ£¬ÉÏÃæµÄmyStrÀàÐÍΪstring£¬¶østrObjÀàÐÍΪobject¡£
Èç¹ûÏëÖªµÀ×Ö·û´®µÄ³¤¶È£¬Ê¹ÓÃÆälengthÊôÐÔ£ºstring.length¡£
µÃµ½×Ö·û´®µÄÖ¸¶¨Î»ÖõÄ×Ö·ûʹÓ÷½·¨£ºstring.charAt(index);
Èý¡¢×Ö·û´®µÄÆ´½Ó
ÎÊÌ⣺
½«Á½¸ö»ò¶à¸ö×Ö·û´®Æ´½ÓΪһ¸ö´óµÄ×Ö·û´®
½â¾ö·½°¸£º
·Ç³£¼òµ¥£¬¾ÍÓÃÒ»¸ö"+"½«Á½¸ö×Ö·û´®"Ïà¼Ó"£º
var longString = "One piece " + "plus one more piece.";
Òª½«¶à¸ö×Ö·û´®ÀÛ»ýΪһ¸ö×Ö·û´®£¬»¹¿ÉÒÔʹÓÃ"+="²Ù×÷·û£º
var result = "";
result += "My name is Anders"
result += " and my age is 25"; &nbs
Ïà¹ØÎĵµ£º
µ¥µ÷µÄÍøÕ¾Ê×Ò³±³¾°¿´¶àÁ˲»ÃâÓÐдÑá·³£¬Èç¹ûÓû§×Ô¼ºÃ¿Ë¢ÐÂÒ»´ÎÒ³Ãæ±³¾°¿ÉÒÔ¸ü»»Ò²ÐíÄÜΪÕâÖÖµ¥µ÷Ìíһ˿µÄÐÂÆæ¡£ÕâÖ»ÐèÓÃÒ»¸öJavaScript·½·¨¾Í¿ÉÒԸ㶨£¬Í¨¹ýËæ»úº¯ÊýÔÚÎÒÃǵÄÒ»×éͼƬÖÐËæ»úµÄÑ¡Ò»ÕÅ×÷Ϊ±³¾°¡£
ÏÂÃæÊÇJavaScript´úÂ룺
view plaincopy to clipboardprint?
<mce:script type="text/javascript" ......
.×Ö·û´®(String)
1.ÉùÃ÷
var myString = new String("Every good boy does fine.");
var myString = "Every good boy does fine.";
2.×Ö·û´®Á¬½Ó
var myString = "Every " + "goo ......
http://blog.csdn.net/cyai/archive/2009/05/25/4213956.aspx
JS×Ô´øº¯Êý
concat
½«Á½¸ö»ò¶à¸ö×Ö·ûµÄÎı¾×éºÏÆðÀ´£¬·µ»ØÒ»¸öеÄ×Ö·û´®¡£
var a = "hello";
var b = ",world";
var c = a.concat(b);
alert(c);
//c = "hello,world"
indexOf
·µ»Ø×Ö·û´®ÖÐÒ»¸ö×Ó´®µÚÒ»´¦³öÏÖµÄË÷Òý£¨´Ó×óµ½ÓÒËÑË÷£©¡£Èç¹ûÃ»Ó ......
function isTrueName(s) { var patrn=/^[a-zA-Z]{1,30}$/; if (!patrn.exec(s)) return false return true } }} //УÑéÃÜÂ룺ֻÄÜÊäÈë6-20¸ö×Öĸ¡¢Êý×Ö¡¢Ï»®Ïß
function isPasswd(s)
{
var patrn=/^(\w){6,20}$/;
if (!patrn.exec(s)) return false
return true
}
//УÑéÆÕͨµç»°¡¢´«ÕæºÅÂ룺¿ÉÒÔ ......