javascript Ìæ»»¿Õ¸ñ
1.×Ôhttp://jorkin.reallydo.com/article.asp?id=275
µÚÒ»´Î·¢ÏÖJavaScriptÖÐreplace() ·½·¨Èç¹ûÖ±½ÓÓÃstr.replace("-","!") Ö»»áÌæ»»µÚÒ»¸öÆ¥ÅäµÄ×Ö·û.
¶østr.replace(/\-/g,"!")Ôò¿ÉÒÔÈ«²¿Ìæ»»µôÆ¥ÅäµÄ×Ö·û(gΪȫ¾Ö±êÖ¾)¡£
replace()
The replace() method returns the string that results when you replace text matching its first argument
(a regular expression) with the text of the second argument (a string).
If the g (global) flag is not set in the regular expression declaration, this method replaces only the first
occurrence of the pattern. For example,
var s = "Hello. Regexps are fun.";s = s.replace(/\./, "!"); // replace first period with an exclamation pointalert(s);
produces the string “Hello! Regexps are fun.” Including the g flag will cause the interpreter to
perform a global replace, finding and replacing every matching substring. For example,
var s = "Hello. Regexps are fun.";s = s.replace(/\./g, "!"); // replace all periods with exclamation pointsalert(s);
yields this result: “Hello! Regexps are fun!”
ËùÒÔ¿ÉÒÔÓÃÒÔϼ¸ÖÖ·½Ê½.£º
string.replace(/reallyDo/g, replaceWith);
string.replace(new RegExp(reallyDo, 'g'), replaceWith);
string£º×Ö·û´®±í´ïʽ°üº¬ÒªÌæ´úµÄ×Ó×Ö·û´®¡£
reallyDo£º±»ËÑË÷µÄ×Ó×Ö·û´®¡£
replaceWith£ºÓÃÓÚÌæ»»µÄ×Ó×Ö·û´®¡£
<mce:script type="text/javascript"><!--
String.prototype.replaceAll = function(reallyDo, replaceWith, ignoreCase) {
if (!RegExp.prototype.isPrototypeOf(reallyDo)) {
return this.replace(new RegExp(reallyDo, (ignoreCase ? "gi": "g")), replaceWith);
} else {
return this.replace(reallyDo, replaceWith);
}
}
// --></mce:script>
±¾ÎÄÀ´Ô´ÓÚ KinJAVAÈÕÖ¾ (http://jorkin.reallydo.com)
ÔÎĵØÖ·: http://jorkin.reallydo.com/article.asp?id=275
2.×Ôhttp://yueguangyuan.javaeye.com/blog/31744
·½·¨£º string.replace(new RegExp(oldString,"gm"),newString))
gm g=global, m=multiLine £¬ ´óÖÂÉÏ·½·¨¾ÍÊÇÕâÑùµÄ£¬¿ÉÒÔʵÏÖ
Ïà¹ØÎĵµ£º
·â×°£ºÍ¨¹ý±Õ°ü²ÅËãµÄÉÏÊÇÕæÕýÒâÒåÉϵķâ×°
<script type="text/javascript">
function myInfo(){
var name ="ÀÏÓã",age =27;
var myInfo = "my name is" + name + "i am" + age  ......
ÕâÀïÃæµÄreturnº¬ÓÐһЩϸ½Ú֪ʶ£º
ÀýÈ磺onClick='return add_onclick()'Óë onClick='add_onclick()'µÄÇø±ð
JAVASCRIPTÔÚʼþÖе÷Óú¯ÊýʱÓÃreturn·µ»ØÖµÊµ¼ÊÉÏÊǶÔwindow.event.returnvalue½øÐÐÉèÖá£
¶ø¸ÃÖµ¾ö¶¨Á˵±Ç°²Ù×÷ÊÇ·ñ¼ÌÐø¡£
µ±·µ»ØµÄÊÇtrueʱ£¬½«¼ÌÐø²Ù×÷¡£
µ±·µ»ØÊÇfalseʱ£¬½«ÖжϲÙ×÷¡£
¶øÖ±½ÓÖ´ÐÐʱ£ ......
·½·¨Ò»¡¢
NPN_GetURL(m_Instance, "javascript:test()", NULL);
·½·¨¶þ¡¢
NPVariant rval;
NPN_InvokeDefault(m_Npp, objectDisconnect ,NULL, 0,&rval);
NPN_ReleaseVariantValue(&rval);
ÒÔÏÂÊÇjavascript
<script type="text/javascript">
&nb ......
ºÜ¶àÈ˶¼²»Ô¸Òâдjavascript´úÂ룬ÎÒ¾õµÃÖ÷ÒªÔÒòÔÚÓÚjavascript´úÂë±È½ÏÁãË飬ɿ¼°µÄÖªÊ¶Ãæ±È½Ï¹ã£¬ÒªÐ´ºÃjavascript´úÂ룬¾Í²»µÃ²»Á˽âhtml£¬cssµÈ£¬ËùÒÔҪѧºÃjavascript²¢²»ÊÇÒ»¼þÈÝÒ×µÄÊ¡£Èç¹ûÒªÊÇÓбȽϺõĿª·¢¹¤¾ßµÄ»°£¬ÏàÐÅ´ó¼ÒѧÆðÀ´»á¼òµ¥Ò»Ð©¡£ÏÂÃæ¸ø´ó¼Ò½éÉÜһЩѧϰjavascriptµÄ¹¤¾ß£º
1¡¢ÈçºÎ¿ìËÙ¿´ ......
1. ×ÜÊÇʹÓà ‘var’
ÔÚJavaScript
ÖУ¬±äÁ¿²»ÊÇÈ«¾Ö·¶Î§µÄ¾ÍÊǺ¯Êý·¶Î§µÄ£¬Ê¹ÓÔvar”¹Ø¼ü´Ê½«ÊDZ£³Ö±äÁ¿¼ò½àÃ÷Á˵Ĺؼü¡£µ±ÉùÃ÷Ò»¸ö»òÕßÊÇÈ«¾Ö»òÕßÊǺ¯Êý¼¶£¨function-level£©µÄ±äÁ¿£¬Ðè×ÜÊÇǰÖÔvar”¹Ø¼ü´Ê£¬ÏÂÃæµÄÀý×Ó½«Ç¿µ÷²»ÕâÑù×öDZÔÚµÄÎÊÌâ¡£
²»Ê¹Óà Var Ôì³ÉµÄÎÊÌâ
var i=0; ......