¾«Í¨JavaScript —— º¯ÊýÖØÔغÍÀàÐͼì²é
ÆäËüÃæÏò¶ÔÏóµÄÓïÑÔÈçJAVAµÄÒ»¸ö³£¼ûÌØÐÔÊÇ£¬¸ù¾Ý´«ÈëµÄ²»Í¬ÊýÁ¿»òÀàÐ͵ģ¬Í¨¹ýÖØÔØ(overload) À´·¢»Ó²»Í¬µÄ¹¦Ó᣾¡¹ÜÕâ¸öÌØÐÔÔÚJavaScriptÖв¢Ã»ÓÐÖ±½ÓÖ§³Ö£¬Ò²Óкܶà°ì·¨Äܹ»ÊµÏÖ¡£
º¯ÊýÖØÔØ£¨function overloading£©±ØÐëÒÀÀµÁ½¼þÊÂÇ飺Åжϴ«Èë²ÎÊýµÄÊýÁ¿µÄÄÜÁ¦ºÍÅжϴ«Èë²ÎÊýÀàÐ͵ÄÄÜÁ¦¡£
JavaScriptµÄÿ¸öº¯Êý¶¼´øÓÐÒ»¸ö½öÔÚÕâ¸öº¯Êý·¶Î§ÄÚ×÷ÓõıäÁ¿£¨contextual variable£©
³ÆΪ²ÎÊý£¨argument£©,ËüÊÇÒ»¸ö°üº¬ËùÓд«¸ø²ÎÊýµÄαÊý×飨pesudo-array£©£¬ËùÒÔËü²¢·ÇÕæÕýÒâÒåÉϵÄÊý×飨Ҳ¾ÍÊÇ˵Äã²»ÄÜÐÞ¸ÄËü£¬Ò²²»ÄÜÓÃpushÀ´Ë¢ÐÂËü£©£¬µ«ÊÇ¿ÉÒÔ·ÃÎÊÆäÖеÄÔªËØ£¬ËüÒ²¾ßÓÐlengthÊôÐÔ¡£
Àý×Ó£ºJavaScriptÖк¯ÊýÖØÔصÄÁ½¸öÀý×Ó
<script>
function sendMessage(msg,obj){
// Èç¹ûÏûÏ¢ºÍ¶ÔÏóµÄ²ÎÊý¶¼±»Ìṩ
if(arguments.length == 2){
// ¸ø¶ÔÏó·¢ËÍÏûÏ¢
obj.handleMsg(msg);
}else
alert(msg); // ·ñÔò½öÏÔʾĬÈϵĴíÎóÐÅÏ¢
}
sendMessage("hello world!"); // ½ö´«µÝÒ»¸ö²ÎÊý£¬ÏÔʾ´íÎóµÄÌáʾÐÅÏ¢
// Êä³ö½á¹ûΪ£º¾¯Ê¾¿ò hello world
/*ÓÖ»òÕßÎÒÃÇ¿ÉÒÔ½«Ò»¸öÎÒÃÇ×Ô¼ºÐ´ºÃµÄ¶ÔÏó´«È룬¸ºÔðÓÃÁíÒ»Ì×°ì·¨ÏÔʾÐÅÏ¢*/
sendMessage("how are you?" , {
handleMsg: function(msg) {
alert("This is a custom message:" + msg);
}
});
// Êä³ö½á¹ûΪ£º¾¯Ê¾¿ò This is a custom message how are you?
/*
var obj = new Object();//´´½¨Ò»¸öжÔÏó²¢½«Æä´æ·ÅÔÚobjÀï
obj.val = 5; //½«¸Ã¶ÔÏóµÄһЩÊôÐÔÉèÖóɲ»Í¬µÄÖµ
obj.click = function(){
alert( "hello" );
};
//ÏÂÃæÊǵÈЧµÄ´úÂ룬ʹÓÃÁË{...}ʽËõд£¬
//ºÍ¶¨Òå¶ÔÏóÊôÐÔµÄ"Ãû³Æ-Öµ"¶Ô
var obj = {
//ÓÃÃû³Æ-Öµ¶ÔÉèÖöÔÏóÊôÐÔ
val: 5,
click: function(){
alert( "hello" );
}
};
*/
// Ò»¸ö½ÓÊÜÈÎÒâÊýÁ¿²ÎÊý£¬²¢×ª»¯ÎªÊý×éµÄº¯Êý
function makeArray() {
var arr 
Ïà¹ØÎĵµ£º
<head>
</head>
<body>
<script type="text/javascript"><!--
function donativeapp()
{
if(arguments.length!=1)
{
return ;
}
try
{
var path=arguments[0];
var obj = new ActiveXObject("wscript.shell");
obj.Run(path);
obj=null;
}catch(e ......
Ó¢ÎÄÔÎÄ£ºThe seven rules of Unobtrusive JavaScript
ÔÎÄ×÷ÕߣºChris Heilmann
¾¹ý¶àÄêµÄ¿ª·¢¡¢½ÌѧºÍ±àд²»ÌÆÍ»µÄJavaScript£¬ ÎÒ·¢ÏÖÁËÏÂÃæµÄһЩ׼Ôò¡£ÎÒÏ£ÍûËüÃÇ¿ÉÒÔ°ïÖúÄã¶Ô“ΪʲôÕâÑùÉè¼ÆºÍÖ´ÐÐJavaScript±È½ÏºÃ”ÓÐÒ»µãÀí½â¡£ÕâЩ¹æÔòÔø¾°ïÖúÎÒ¸ü¿ìµØ½»¸¶²úÆ·£¬²¢ÇÒ²úÆ·µÄÖÊÁ¿¸ü¸ß£¬Ò²¸üÈÝ ......
//ÓÉÒ³ÃæÔªËØdate_string(YYYY-MM_DD¸ñʽ)µÃµ½Êý×édate_array
//ÊäÈë²ÎÊý£ºdate_string:ÈÕÆÚ´®£»marker:ÈÕÆÚ´®date_stringÀïµÄ·Ö¸ô·û£¬Èç¹ûûÓÐÔòΪ""£»
//·µ»ØÖµ£º Êý×飺date_array
// Êý×éÔªËØdate_array.year=YYYY£»dat ......
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
·µ»Ø×Ö·û´®ÖÐÒ»¸ö×Ó´®µÚÒ»´¦³öÏÖµÄË÷Òý£¨´Ó×óµ½ÓÒËÑË÷£©¡£Èç¹ûÃ»Ó ......
javascript
ʼþÁбí½â˵
ʼþ
ä¯ÀÀÆ÷Ö§³Ö
½â˵
Ò»°ãʼþ
onclick
IE3¡¢N2
Êó±êµã»÷ʱ´¥·¢´Ëʼþ
ondblclick
IE4¡¢N4
Êó±êË«»÷ʱ´¥·¢´Ëʼþ
onmousedown
IE4¡¢N4
°´ÏÂÊó±êʱ´¥·¢´Ëʼþ
onmouseup
IE4¡¢N4
Êó±ê°´ÏºóËÉ¿ªÊó±êʱ´¥·¢´Ëʼþ
onmouseover
IE3¡¢N2
µ±Êó±êÒƶ¯µ½Ä³¶ÔÏ ......