Javascript ÖÐ String.replace( ) µÄÃîÓÃ
<script language="javascript">
<!--
String.prototype.replaceAll = stringReplaceAll;
function stringReplaceAll(AFindText,ARepText){
raRegExp = new RegExp(AFindText,"g");
return this.replace(raRegExp,ARepText)
}
var content = "%sfasf%sfd%asdfsadf%1111%"
// °Ñ ËùÓÐµÄ % Ì滻Ϊ #
document.write(content.replaceAll("%","#"));
//-->
</script>
String.replace ( ) ¼ò½é
Óï·¨£º
Code:
string.replace (regexp, replace ment)
regexp £ºÄúÒªÖ´ÐÐÌæ»»²Ù×÷µÄÕýÔò±í´ïʽ£¬Èç¹û´«ÈëµÄÊÇÒ»¸ö×Ö·û´®£¬ÄǾͻᵱ×÷ÆÕͨ×Ö·ûÀ´´¦Àí£¬²¢ÇÒÖ»»áÖ´ÐÐÒ»´ÎÌæ»»²Ù×÷£»Èç¹ûÊÇÕýÔò±í´ïʽ£¬²¢ÇÒ´øÓÐ global (g) ÐÞÊηû£¬Ôò»áÌæ»»ËùÓгöÏÖµÄÄ¿±ê×Ö·û£¬·ñÔò£¬½«Ö»Ö´ÐÐÒ»´ÎÌæ»»²Ù×÷¡£
replace ment £ºÄúÒªÌæ»»³ÉµÄ×Ö·û¡£
·µ»ØÖµÊÇÖ´ÐÐÌæ»»²Ù×÷ºóµÄ×Ö·û´®¡£
String.replace ( ) µÄ¼òµ¥Ó÷¨
Code:
var text = "javascript ·Ç³£Ç¿´ó £¡";
text.replace (/javascript /i, "JavaScript ");
// ·µ»Ø£ºJavaScript ·Ç³£Ç¿´ó £¡
String.replace ( ) Ìæ»»ËùÓгöÏÖµÄÄ¿±ê×Ö·û
Code:
var text= "javascript ·Ç³£Ç¿´ó £¡JAVASCRIPT ÊÇÎÒ×îϲ»¶µÄÒ»ÃÅÓïÑÔ £¡";
text.replace (/javascript /ig, "JavaScript ");
// ·µ»Ø£ºJavaScript ·Ç³£Ç¿´ó £¡JavaScript ÊÇÎÒ×îϲ»¶µÄÒ»ÃÅÓïÑÔ £¡
String.replace ( ) ʵÏÖµ÷»»Î»ÖÃ
Code:
var name= "Doe, John";
name.replace (/(\w+)\s*,\s*(\w+)/, "$2 $1");
// ·µ»Ø£ºJohn Doe
String.replace ( ) ʵÏÖ½«ËùÓÐË«ÒýºÅ°üº¬µÄ×Ö·ûÌæ»»³ÉÖÐÀ¨ºÅ°üº¬µÄ×Ö·û
Code:
var text = '"JavaScript " ·Ç³£Ç¿´ó£¡';
text.replace (/"([^"]*)"/g, "[$1]");
// ·µ»Ø£º[JavaScript ] ·Ç³£Ç¿´ó£¡
String.replace ( ) ½«ËùÓÐ×Ö·ûÊ××Öĸ´óд
Code:
var text = 'a journey of a thousand miles begins with single step.';
text.replace (/\b\w+\b/g, function(word) {
return word.substring(0,1).toUpperCase( ) +
 
Ïà¹ØÎĵµ£º
ÔÚ¿ª·¢Öо³£»áÓÐÖ±½Ó¹Ø±ÕÒ³Ãæ²»µ¯³öÈκÎÌáʾµÄÐèÇó£¬ÔÚIE6ÖпÉÒÔÖ±½ÓÏóÏÂÃæÕâÑùд¾Í¿ÉÒÔÁË
<mce:script language=javascript><!--
window.opener=null
window.close()
// --></mce:script>
Õâ¸öÎÊÌâÔÚIE7ÖÐÔòÓпÉÄÜÊdzöÓÚijÖÖ°²È«¿¼ÂÇ£¨ÒòΪÔÚMSä¯ÀÀÆ÷µÄ¾ºÕù¶ÔÊÖFFÖУ¬ÊDz»Äܹرշ ......
ʹÓùýAJAX¼¼ÊõµÄÈ˶¼ÖªµÀ´óÃû¶¦¶¦µÄJQuery¡£ËäÈ»ÎÒÀ´Ñ§Ï°Ö®Ç°Óп´¹ýAJAXµÄÊÓƵ£¬µ«ÄÇʱ¶ÔWEBÓ¦ÓÃÕâ¸ö¶«Î÷»¹±È½ÏÄ£ºý£¬²»Çå³þHTML¡¢JSPÓëServletÊÇÔõô¹¤×÷µÄ£¬ÉõÖÁ²»ÖªµÀJQuery°ü×°µÄÊÇʲô¶«Î÷¡£½ñÈÕµÄѧϰÔÙ½áºÏ×òÌìµÄJavaScriptDOMµÄÄÚÈÝ£¬ÈÃÎÒ¶Ô´ËÊ®·ÖÇåÎú¡£JQueryÔÔò£º“write less, do more.” ......
ÒýÈëÃüÃû¿Õ¼ä֮ǰ£¬Ò»¸öÁ·¢ÈËԱͷÌÛµÄÎÊÌâ¾ÍÊÇÈçºÎ·ÀÖ¹º¯ÊýÃû/ÀàÃûºÍÆäËûÈ˵ijåÍ»£¬ÔÚÒ»¸ö¹«Ë¾ÄÚ²¿ÏîÄ¿×éÖ®¼ä¿ÉÒÔͨ¹ýÃüÃûÔ¤¶¨£¨±ÈÈç¼Óǰ׺
µÈ£©½â¾öÕâ¸öÎÊÌ⣬µ«ÊÇ°ÑÊÓÏ߷ŵ½Õû¸öÈí¼þ¿ª·¢ÁìÓò£¬ÔÚµ±½ñÐ×÷¿ª·¢Ï൱ʢÐеÄʱ´ú£¬Õâ¸öÎÊÌâÈ´ÒÀÈ»´æÔÚ¡£ÔÚʹÓöà¸öµÚÈý·½¿ò¼Ü»òÀà¿âµÄʱºò£¬ÄãΨһÄÜ×÷
µÄ¾ÍÊÇÆíµ»ËüÃǵÄÃüà ......
ʹÓõÄÕýÔò±í´ïʽµÄÀý×Ó£¬µ«ÊÇûÓÐ˵ÕâЩÕýÔò±í´ïʽÈçºÎʹÓã¬ÏÖÔÚ¸ø´ó¼Ò¼¸¸öÀý×Ó£¬´ó¼Ò¿ÉÒÔ¿´¿´¡£
ÀûÓÃÕýÔò±í´ïʽÅжÏÊÇ·ñÊÇ0-9µÄ°¢À²®Êý×Ö
function regIsDigit(fData)
{
var reg = new RegExp("^[0-9]$");
return (reg.test(fData));
}
ÀûÓÃÕâÔò±í´ïʽ»ñÈ¡×Ö·û´®µÄ³¤¶È
function regDataLength(fData) ......
ÓÃÀ´ÅÅÐò¶ÔÏñÊý×éµÄ. ×îºó»¹ÊǾö¶¨ÓÃArray¶ÔÏñµÄsort·½·¨£¬¾¡¹ÜÕâЩ¶¼Ã»ÓÃÉÏ£¬»¹ÊÇ×Ô¼º¼ÇÔÚ¿Õ¼äÀïµ±±Ê¼ÇÓõÄ.
¿ìËÙÅÅÐò£¬ÓÅ»¯µÄ¿ìËÙÅÅÐò£¬ÍüÁËÃû×ÓµÄÅÅÐò·½·¨£¬¶ÔÏñÌṩµÄÅÅÐò; ¾ø¶Ô²»ÒªÓÃÆðÅÝ·¨£¬³ý·ÇÊǽÌѧÉú¡£
ΪÁ˲âÊÔ£¬Ð´ÁËÒ»¸öÉú³ÉËæ»ú¶ÔÏñµÄ·½·¨£¬ÓÃÀ´Éú³ÉÒ»¸ö¶ÔÏñ£¬¶ÔÏñÖÐÓÐÒ»¸öÊôÐÔ a £¬a µÄֵΪһ¸öËæ»úÊ ......