ÈçºÎÕýÈ·µÄ¼ÓÔØjavascriptÎļþ
1£© Ϊʲô¼ÓÔØjavascriptÎļþºÜÖØÒª£¿
javascriptÎļþÊDZȽÏÌØÊâµÄ£¬ÒòΪä¯ÀÀÆ÷¼ÓÔØjavascriptÊÇ´®Ðеġ£ÒÔΪ×ÅÔÚ¼ÓÔØJavascriptÎļþµÄʱºò£¬ÆäËûÒ»ÇÐ×ÊÔ´µÄÏÂÔØ°üÀ¨Ò³ÃæµÄÏÔʾ¶¼»á±»×èÈû¡£
2£© ÈçºÎÕýÈ·µÄ¼ÓÔØJavaScript£¿
a. ½«JavaScriptÎļþ·ÅÔÚÒ³ÃæµÄ×îºó
ÒòΪJavaScriptµÄ¼ÓÔØ»á×èÈûÒ³ÃæµÄÏÔʾ£¬ËùÒÔ½«JavaScriptÎļþ·ÅÖÃÔÚÒ³ÃæµÄ×îºó£¬Ò²¾ÍÊÇ<body>±êÇ©½áÊøÇ°¡£ÕâÑùÓû§¿ÉÒÔ¸ü¿ìµÄ¿´µ½Ò³ÃæµÄÏÔʾ£¬¿ÉÒÔÓиüºÃµÄÓû§ÌåÑé¡£
b. ²¢ÐеļÓÔØJavaScript
Èç¹ûʹÓÃÆÕͨµÄ<script>±êÇ©À´ÒýÓÃÍⲿµÄJSÎļþ£¬ÄÇôJSÎļþµÄÏÂÔØÊÇ´®Ðеģ¬ÕâÑùͨ³£Ð§ÂÊ»á·Ç³£µÍ¡£ÍƼöʹÓÃLABjsÀ´¼ÓÔØJavaScript£¬¿ÉÒÔ´ïµ½JSÎļþµÄ²¢ÐÐÏÂÔØ£¬µ«Í¬Ê±ÓÖÓлúÖÆÀ´±£Ö¤JSÎļþÖ´ÐеÄ˳Ðò¡£
ÏÂÃæ¾ÍÊÇÒ»¸öʹÓÃLABjÀ´¼ÓÔØJavaScriptµÄÀý×Ó
<script>
$LAB
.script("framework.js").wait()
.script("plugin.framework.js")
.script("myplugin.framework.js")
.wait(function(){
myplugin.init();
framework.init();
framework.doSomething();
});
</script>
¾ßÌå¿ÉÒԲ鿴LABjµÄ¹Ù·½ÍøÕ¾£ºhttp://labjs.com/
c. Lazy load
Õâ¸öÍùÍùÊǽ²ÆðÀ´±È½ÏÈÝÒ×£¬×öÆäËû±È½ÏÄÑ¡£ÔÀíºÜ¼òµ¥£¬¾ÍÊÇÒ³ÃæÏÔʾµÄʱºò£¬Ö»¼ÓÔØÐèÒªµÄJSÎļþ£¬È»ºóÔÚÓû§²Ù×÷µÄʱºòÔÙ¼ÓÔØÐèÒªµÄJSÎļþ¡£
d. ÕýÈ·µÄѹËõJSÎļþ
ʹÓÃJSMin»òÕßGoogle ClosureÀ´Ñ¹ËõJSÎļþ£¬Õâ¸öÍùÍù¿ÉÒÔ´ó´ó¼õÉÙJSÎļþµÄ´óС¡£
±¾ÎÄÀ´×ÔCSDN²©¿Í£¬×ªÔØÇë±êÃ÷³ö´¦£ºhttp://blog.csdn.net/Danwang/archive/2010/02/03/5286576.aspx
Ïà¹ØÎĵµ£º
JavaScriptÀï×Ö·û´®ÀàÐÍת»»³ÉÈÕÆÚÀàÐÍ£º
Èç¹û×Ö·û´®ÖÐÓпոñ»òÊÇÆäËû·Ö¸î·û·Ö¸î£¬¿ÉÒÔÓÃsplit·½·¨ÏȲð·Ö£¬·µ»ØÒ»¸öÊý×飬ÔÙ°ÑÕâ¸öÊý×éÀïµÄÄêÔÂÈÕ×÷Ϊ²ÎÊý´«µ½new Date()ÀïÉú³ÉÈÕÆÚÀàÐÍ£»
Èç¹ýûÓÐÌØÊâ·Ö¸ô·û£¬¿ÉÒÔÓÃsubstr£¨x£¬y£©·½·¨À´È¡×Ó×Ö·û´®À´Éú³ÉÈÕÆÚ£¬substr£¨x£¬y£©Àx±íʾȡ×Ö´®µÄ¿ªÊ¼Î»Öã¬y±íʾ×Ó´®µÄ³ ......
javaScript
ÖÐµÄ call
() ÊÇÒ»¸öÆæÃîµÄ·½·¨£¬µ«Ò²ÊÇÒ»¸öÈÃÈËÃÔ»óµÄ·½·¨£¬ÏÈ¿´Ò»Ï¹ٷ½µÄ½âÊÍ£º
call
·½·¨
Çë²ÎÔÄ
Ó¦ÓÃÓÚ£ºFunction ¶ÔÏó
񻂗
°æ±¾ 5.5
µ÷ÓÃÒ»¸ö¶ÔÏóµÄÒ»¸ö·½·¨£¬ÒÔÁíÒ»¸ö¶ÔÏóÌæ»»µ±Ç°¶ÔÏó¡£
call
([thisObj[,arg1[, arg2[, [,.argN]]]]])
²ÎÊý
thisObj
¿ÉÑ¡Ïî¡£½«±»ÓÃ×÷µ±Ç ......
String.prototype.Trim=function(){
returnthis.replace(/(^\s*)|(\s*$)/g,"");
}
String.prototype.LTrim=function(){
returnthis.replace(/(^\s*)/g,"");
}
String.prototype.RTrim=function(){
returnthis.replace(/(\s*$)/g,"");
} ......
JavaScript·½·¨ºÍ¼¼ÇÉ´óÈ«
1£º»ù´¡ÖªÊ¶
1 ´´½¨½Å±¾¿é
1: <script language=”JavaScript”>
2: JavaScript code goes here
3: </script>
2 Òþ²Ø½Å±¾´úÂë
1: <script language=”JavaScript”>
2: ......
<script type="text/javascript">
function dayChange(year,month,day){
var selectYear = document.getElementById(year);
var selectMonth = document.getElementById(month);
var selectDay = document.getElementById(day);
va ......