ÉîÈëÈÏʶjavascriptÖеÄevalº¯Êý
ÉîÈëÈÏʶjavascriptÖеÄevalº¯Êý
·ÖÀࣺ¼¼ÊõרÇøʱ¼ä£º2007-5-21 15:04:58×÷ÕߣºsupNate
·¢ÏÖΪ±¾ÎÄÆðÒ»¸öºÏÊʵıêÌ⻹²»ÊÇÄÇôÈÝÒ×£¬ºÇºÇ£¬ËùÒÔÔÚ´ËÏÈ˵Ã÷ϱ¾ÎĵÄÁ½¸öÄ¿µÄ£º
£¨1£©½éÉÜjavascriptÖеÄevalº¯ÊýµÄÓ÷¨
£¨2£©ÈçºÎÔÚº¯ÊýÄÚÖ´ÐÐÈ«¾Ö´úÂë
►ÏÈÀ´ËµevalµÄÓ÷¨£¬ÄÚÈݱȽϼòµ¥£¬ÊìϤµÄ¿ÉÒÔÌø¹ý¡£
evalº¯Êý½ÓÊÕÒ»¸ö²ÎÊýs£¬Èç¹ûs²»ÊÇ×Ö·û´®£¬ÔòÖ±½Ó·µ»Øs¡£·ñÔòÖ´ÐÐsÓï¾ä¡£Èç¹ûsÓï¾äÖ´Ðнá¹ûÊÇÒ»¸öÖµ£¬Ôò·µ»Ø´ËÖµ£¬·ñÔò·µ»Øundefined¡£
ÐèÒªÌرð×¢ÒâµÄÊǶÔÏóÉùÃ÷Óï·¨“{}”²¢²»ÄÜ·µ»ØÒ»¸öÖµ£¬ÐèÒªÓÃÀ¨ºÅÀ¨ÆðÀ´²Å»á·µ»ØÖµ£¬¼òµ¥Ê¾ÀýÈçÏ£º
var code1='"a" + 2'; //±í´ïʽ
var code2='{a:2}'; //Óï¾ä
alert(eval(code1)); //->'a2'
alert(eval(code2)); //->undefined
alert(eval('(' + code2 + ')')); //->[object Object]
¿ÉÒÔ¿´µ½£¬¶ÔÓÚ¶ÔÏóÉùÃ÷Óï¾äÀ´Ëµ£¬½ö½öÊÇÖ´ÐУ¬²¢²»ÄÜ·µ»ØÖµ¡£ÎªÁË·µ»Ø³£Óõē{}”ÕâÑùµÄ¶ÔÏóÉùÃ÷Óï¾ä£¬±ØÐëÓÃÀ¨ºÅÀ¨×¡£¬ÒÔ½«Æäת»»Îª±í´ïʽ£¬²ÅÄÜ·µ»ØÆäÖµ¡£ÕâÒ²ÊÇʹÓÃJSONÀ´½øÐÐAjax¿ª·¢µÄ»ù±¾ÔÀíÖ®Ò»¡£ÔÚÀý×ÓÖпÉÒÔÇå³þµÄ¿´µ½£¬µÚ¶þ¸öalertÓï¾äÊä³öµÄÊÇundefined£¬¶øµÚÈý¸ö¼ÓÁËÀ¨ºÅºóÊä³öµÄÊÇÓï¾ä±íʾµÄ¶ÔÏó¡£
►ÏÖÔÚÀ´Ëµ±¾ÎĵÄÖص㣬ÈçºÎÔÚº¯ÊýÄÚÖ´ÐÐÈ«¾Ö´úÂ롣ΪÁË˵Ã÷Õâ¸öÎÊÌ⣬ÏÈ¿´Ò»¸öÀý×Ó£º
var s='global'; //¶¨ÒåÒ»¸öÈ«¾Ö±äÁ¿
function demo1(){
eval('var s="local"');
}
demo1();
alert(s); //->global
ºÜºÃÀí½â£¬ÉÏÃæµÄdemo1º¯ÊýµÈ¼ÛÓÚ£ºfunction demo1(){var s='local';}£¬ÆäÖж¨ÒåÁËÒ»¸ö¾Ö²¿±äÁ¿s¡£
ËùÒÔ×îºóµÄÊä³öÊÇglobal²¢²»ÊÇʲôÆæ¹ÖµÄÊÂÇ飬±Ï¾¹´ó¼Ò¶¼ÄܺÜÇå³þµÄÇø·Ö¾Ö²¿±äÁ¿ºÍÈ«¾Ö±äÁ¿¡£
×ÐϸÌå»áһϣ¬¿ÉÒÔ·¢ÏÖev
Ïà¹ØÎĵµ£º
1¡¢rcbdyctl
view plaincopy to clipboardprint?
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=gb2312">
<title>JS»ñÈ¡¿Í»§¶ËIP</title>
</head>
<b ......
ä¯ÀÀÆ÷¶ÔÏó
ä¯ÀÀÆ÷¶ÔÏó¾ÍÊÇÍøÒ³ºÍä¯ÀÀÆ÷±¾Éí¸÷ÖÖʵÌåÔªËØÔÚJavaScript³ÌÐòÖеÄÌåÏÖ¡£ÕâÑùµÄä¯ÀÀÆ÷¶ÔÏóÖ÷Òª°üÀ¨ÒÔϼ¸¸ö
¡ñ Navigator£º¹ÜÀíÕßµ±Ç°Ê¹ÓÃä¯ÀÀÆ÷µÄ°æ±¾ºÅ¡¢ÔËÐеÄƽ̨ÒÔ¼°ä¯ÀÀÆ÷ʹÓõÄÓïÑÔµÈÐÅÏ¢¡£
¡ñ Windows¶ÔÏ󣺴¦ÓÚÕû¸ö´ÓÊô±íµÄ×¼¶Î»Öá£Ã¿Ò»¸öÕâÑùµÄ¶ÔÏó´ú±íÒ»¸öä¯ÀÀ ......
Dojo
Ò»¸öÇ¿´óµÄÃæÏò¶ÔÏójavascript¿ò¼Ü¡£
Ö÷ÒªÓÉÈý´óÄ£¿é×é³É£ºCore¡¢Dijit¡¢DojoX¡£
CoreÌṩ Ajax£¬events£¬packaging£¬CSS-based querying£¬animations£¬JSONµÈÏà¹Ø²Ù×÷API¡£
Dijit ......
Êý×éÓÐËÄÖÖ¶¨ÒåµÄ·½Ê½
ʹÓù¹Ô캯Êý£º
var a = new Array();
var b = new Array(8);
var c =
new Array("first", "second", "third");
»òÕßÊý×éÖ±½ÓÁ¿£º
var d = ["first",
"second", "third"];
ÊôÐÔ
ArrayÖ»ÓÐÒ»¸öÊôÐÔ£¬¾ÍÊÇlength£¬length±íʾµ ......
ת×Ôwww.cnbeta.com/articles/108735.htm
JavaScript ÊÇÒ»¿îÇ¿´óµÄ¹ã·ºÔËÓÃÓÚÏÖ´úWebÕ¾µã¼°Ó¦ÓõĽű¾ÓïÑÔ¡£×÷Ϊһ¸ö¼¼ÒÕ¾«Õ¿µÄ Web ¿ª·¢Õߣ¬ÕÆÎÕJavaScript¿ÉÒÔÔöÇ¿Óû§µÄʹÓÃÌåÑ飬Ìṩ½»»¥¼°¸»¿Í»§¶ËµÈ¹¦ÄÜ¡£
¾¡¹ÜJavaScript µÄÓï·¨·Ç³£¼òµ¥£¬µ«¶ÔÓÚд³ÌÐò¶øÑÔÈÔÈ»ÊÇÀ§ÄÑÖØÖØ£¬¾ÍÊÇÒòΪËüµÄÔËÐл·¾³£º»ùÓÚ ......