JavaScript ÃæÏò¶ÔÏó
(תhttp://www.javaeye.com/topic/155109)
JavaScript ÊÇÃæÏò¶ÔÏóµÄ¡£µ«ÊDz»ÉÙÈ˶ÔÕâÒ»µãÀí½âµÃ²¢²»È«Ãæ¡£
ÔÚ JavaScript ÖУ¬¶ÔÏó·ÖΪÁ½ÖÖ¡£Ò»ÖÖ¿ÉÒÔ³ÆΪ“ÆÕͨ¶ÔÏ󔣬¾ÍÊÇÎÒÃÇËùÆÕ±éÀí½âµÄÄÇЩ£ºÊý×Ö¡¢ÈÕÆÚ¡¢Óû§×Ô¶¨ÒåµÄ¶ÔÏó£¨È磺{}£©µÈµÈ¡£
»¹ÓÐÒ»ÖÖ£¬³ÆΪ“·½·¨¶ÔÏ󔣬¾ÍÊÇÎÒÃÇͨ³£¶¨ÒåµÄ function¡£Äã¿ÉÄܾõµÃÆæ¹Ö£º·½·¨¾ÍÊÇ·½·¨£¬Ôõô³ÉÁ˶ÔÏóÁË£¿µ«ÊÇÔÚ JavaScript ÖУ¬·½·¨µÄÈ·ÊDZ»µ±³É¶ÔÏóÀ´´¦ÀíµÄ¡£ÏÂÃæÊÇÒ»¸ö¼òµ¥µÄÀý×Ó£º
Js´úÂë
function func() {alert('Hello!');}
alert(func.toString());
function func() {alert('Hello!');}
alert(func.toString());
ÔÚÕâ¸öÀý×ÓÖУ¬func ËäÈ»ÊÇ×÷Ϊһ¸ö·½·¨¶¨ÒåµÄ£¬µ«Ëü×ÔÉíÈ´°üº¬Ò»¸ö toString ·½·¨£¬ËµÃ÷ func ÔÚÕâÀïÊDZ»µ±³ÉÒ»¸ö¶ÔÏóÀ´´¦ÀíµÄ¡£¸ü׼ȷµÄ˵£¬func ÊÇÒ»¸ö“·½·¨¶ÔÏó”¡£ÏÂÃæÊÇÀý×ӵļÌÐø£º
Js´úÂë
func.name = “I am func.”;
alert(func.name);
func.name = “I am func.”;
alert(func.name);
ÎÒÃÇ¿ÉÒÔÈÎÒâµÄΪ func ÉèÖÃÊôÐÔ£¬Õâ¸ü¼ÓÖ¤Ã÷ÁË func ¾ÍÊÇÒ»¸ö¶ÔÏó¡£ÄÇô·½·¨¶ÔÏóºÍÆÕͨ¶ÔÏóµÄÇø±ðÔÚÄÄÀïÄØ£¿Ê×ÏÈ·½·¨¶ÔÏóµ±È»ÊÇ¿ÉÒÔÖ´Ðеģ¬ÔÚËüºóÃæ¼ÓÉÏÒ»¶ÔÀ¨ºÅ£¬¾ÍÊÇÖ´ÐÐÕâ¸ö·½·¨¶ÔÏóÁË¡£
Js´úÂë
func();
func();
ËùÒÔ£¬·½·¨¶ÔÏó¾ßÓжþÖØÐÔ¡£Ò»·½ÃæËü¿ÉÒÔ±»Ö´ÐУ¬ÁíÒ»·½ÃæËüÍêÈ«¿ÉÒÔ±»µ±³ÉÒ»¸öÆÕͨ¶ÔÏóÀ´Ê¹Óá£ÕâÒâζ×ÅʲôÄØ£¿ÕâÒâζ×Å·½·¨¶ÔÏóÊÇ¿ÉÒÔÍêÈ«¶ÀÁ¢ÓÚÆäËû¶ÔÏó´æÔڵġ£ÕâÒ»µãÎÒÃÇ¿ÉÒÔͬ Java ±È½Ïһϡ£ÔÚ Java ÖУ¬·½·¨±ØÐëÔÚijһ¸öÀàÖж¨Ò壬¶ø²»Äܵ¥¶À´æÔÚ¡£¶ø JavaScript ÖоͲ»ÐèÒª¡£
·½·¨¶ÔÏó¶ÀÁ¢ÓÚÆäËû·½·¨£¬¾ÍÒâζ×ÅËüÄܹ»±»ÈÎÒâµÄÒýÓúʹ«µÝ¡£ÏÂÃæÊÇÒ»¸öÀý×Ó£º
Js´úÂë
function invoke(f) {
f();
}
invoke(func);
function invoke(f) {
f();
}
invoke(func);
½«Ò»¸ö·½·¨¶ÔÏó func ´«µÝ¸øÁíÒ»¸ö·½·¨¶ÔÏó invoke£¬ÈúóÕßÔÚÊʵ±µÄʱºòÖ´ÐÐ func¡£Õâ¾ÍÊÇËùνµÄ“»Øµ÷”ÁË¡£ÁíÍ⣬·½·¨¶ÔÏóµÄÕâÖÖÌØÊâÐÔ£¬Ò²Ê¹µÃ this ¹Ø¼ü×Ö²»ÈÝÒ×°ÑÎÕ¡£Õâ·½ÃæÏà¹ØÎÄÕ²»ÉÙ£¬ÕâÀﲻ׸ÊöÁË¡£
³ýÁË¿ÉÒÔ±»Ö´ÐÐÒÔÍ⣬·½·¨¶ÔÏó»¹ÓÐÒ»¸öÌØÊâµÄ¹¦Ó㬾ÍÊÇËü¿ÉÒÔͨ¹ý new ¹Ø¼ü×ÖÀ´´´½¨ÆÕͨ¶ÔÏ
Ïà¹ØÎĵµ£º
ä¯ÀÀÆ÷£ºIE 8¡¢FF 3.6¡¢Chrome 4.0¡¢Safari 4.0¡¢Opera 10.1
½öÓÐIEä¯ÀÀÆ÷Ö§³ÖHTMLElement.onresize£¨±ÈÈçbody.onresize£©
ÆäËüä¯ÀÀÆ÷Ö»Ö§³Öwindow.onresize
ÏÈ˵IEµÄHTMLElement.onresize
ʹÓÃÇ°ÇëÈ·¶¨ÄãµÄÐÄÔ༰ѪѹÕý³££¬Èç¹ûÄ㶨ÒåÁË
body.onresize = function(){……}»òÕßhtml.onresize = obj.fun;
......
Ñ¡ÔñÔªËØ£ºdocument.getElementsByTagName£¬document.getElementsById,document.getElementsByName¡£
firstChild,lastChild,nextSibling£¬previousSibling
´´½¨ÔªËØ£ºdocument.createElement(),appendChild();
ɾ³ýÔªËØ£ºremoveC ......
javascript²¶»ñ´°¿Ú¹Ø±ÕʼþÓÐÁ½ÖÖ·½·¨
1.ÓÃjavascriptÖØж¨Òå window.onbeforeunload() ʼþ
ÔÚjavascriptÀﶨÒåÒ»¸öº¯Êý¼´¿É
function window.onbeforeunload() { alert("¹Ø±Õ´°¿Ú")}
alert()ʼþ½«»áÔڹرմ°¿ÚÇ°Ö´ÐУ¬ÄãÒ²¿ÉÒÔÓû§¾ö¶¨ÊÇ·ñ¹Ø±Õ´°¿Ú
function window.o ......
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>ÓÃjavascript¶¯Ì¬Ìí¼Óɾ³ýhtmlÔªËØ</title>
<script type="text/javascript"><!--
function $(nodeId) {
re ......
±¾ÎĽ«½éÉܼ¸¸ö³£ÓõÄJavaScriptÑéÖ¤ÕýÔò±í´ïʽ£¬ÕâЩ×ÊÁÏÏ£Íû¶Ô´ó¼ÒÔÚʵ¼Ê±à³Ì¹ý³ÌÖÐÆðµ½°ïÖú×÷Óá£
Æ¥ÅäÖÐÎÄ×Ö·ûµÄÕýÔò±í´ïʽ£º [u4e00-u9fa5]
ÆÀ×¢£ºÆ¥ÅäÖÐÎÄ»¹ÕæÊǸöÍ·ÌÛµÄÊ£¬ÓÐÁËÕâ¸ö±í´ïʽ¾ÍºÃ°ìÁË
Æ¥ÅäË«×Ö½Ú×Ö·û(°üÀ¨ºº×ÖÔÚÄÚ)£º[^x00-xff]
ÆÀ×¢£º¿ÉÒÔÓÃÀ´¼ÆËã×Ö·û´®µÄ³¤¶È£¨Ò»¸öË«×Ö½Ú×Ö·û³¤¶È¼Æ2£¬ASCII×Ö·û ......