Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

JavaScript´¦ÀíJson

JSON(JavaScript Object Notation) ÊÇÒ»ÖÖÇáÁ¿¼¶µÄÊý¾Ý½»»»¸ñʽ£¬Ò×ÓÚÔĶÁºÍ±àд£¬Í¬Ê±Ò²Ò×ÓÚ»úÆ÷½âÎöºÍÉú³É¡£Ëü»ùÓÚECMA262ÓïÑԹ淶£¨1999-12µÚÈý°æ£©ÖÐJavaScript±à³ÌÓïÑÔµÄÒ»¸ö×Ó¼¯¡£ JSON²ÉÓÃÓë±à³ÌÓïÑÔÎ޹صÄÎı¾¸ñʽ£¬µ«ÊÇҲʹÓÃÁËÀàCÓïÑÔ£¨°üÀ¨C£¬ C++£¬ C#£¬ Java£¬ JavaScript£¬ Perl£¬ PythonµÈ£©µÄÏ°¹ß£¬ÕâЩÌØÐÔʹJSON³ÉΪÀíÏëµÄÊý¾Ý½»»»¸ñʽ¡£
JSONµÄ½á¹¹»ùÓÚÏÂÃæÁ½µã
1. "Ãû³Æ/Öµ"¶ÔµÄ¼¯ºÏ ²»Í¬ÓïÑÔÖУ¬Ëü±»Àí½âΪ¶ÔÏó(object)£¬¼Ç¼(record)£¬½á¹¹(struct)£¬×Öµä(dictionary)£¬¹þÏ£±í(hash table)£¬¼üÁбí(keyed list)µÈ
2. ÖµµÄÓÐÐòÁÐ±í ¶àÊýÓïÑÔÖб»Àí½âΪÊý×é(array)
JSONʹÓãº
JSONÒÔÒ»ÖÖÌض¨µÄ×Ö·û´®ÐÎʽÀ´±íʾ JavaScript ¶ÔÏó¡£Èç¹û½«¾ßÓÐÕâÑùÒ»ÖÖÐÎʽµÄ×Ö·û´®¸³¸øÈÎÒâÒ»¸ö JavaScript ±äÁ¿£¬ÄÇô¸Ã±äÁ¿»á±ä³ÉÒ»¸ö¶ÔÏóÒýÓ㬶øÕâ¸ö¶ÔÏó¾ÍÊÇ×Ö·û´®Ëù¹¹½¨³öÀ´µÄ£¬ºÃÏñÓеãÞÖ¿Ú£¬ÎÒÃÇ»¹ÊÇÓÃʵÀýÀ´ËµÃ÷¡£
 ÕâÀï¼ÙÉèÎÒÃÇÐèÒª´´½¨Ò»¸öUser¶ÔÏ󣬲¢¾ßÓÐÒÔÏÂÊôÐÔ
Óû§ID
̞
Óû§Email
Äú¿ÉÒÔʹÓÃÒÔÏÂJSONÐÎʽÀ´±íʾUser¶ÔÏó£º
{"UserID":11, "Name":"Truly", "Email":"zhuleipro¡òhotmail.com"};È»ºóÈç¹û°ÑÕâÒ»×Ö·û´®¸³ÓèÒ»¸öJavaScript±äÁ¿£¬ÄÇô¾Í¿ÉÒÔÖ±½ÓʹÓöÔÏóµÄÈÎÒ»ÊôÐÔÁË¡£
ÍêÕû´úÂë:
<script>
var User = {"UserID":11, "Name":"Truly", "Email":"zhuleipro¡òhotmail.com"};
alert(User.Name);
</script>ʵ¼ÊʹÓÃʱ¿ÉÄܸü¸´ÔÓÒ»µã£¬±ÈÈçÎÒÃÇΪName¶¨Òå¸üÏêϸµÄ½á¹¹£¬Ê¹Ëü¾ßÓÐFirstNameºÍLastName£º
{"UserID":11, "Name":{"FirstName":"Truly","LastName":"Zhu"}, "Email":"zhuleipro¡òhotmail.com"}ÍêÕû´úÂë:
<script>
var User = {"UserID":11, "Name":{"FirstName":"Truly","LastName":"Zhu"}, "Email":"zhuleipro¡òhotmail.com"};
alert(User.Name.FirstName);
</script>ÏÖÔÚÎÒÃÇÔö¼ÓÒ»¸öеÄÐèÇó£¬ÎÒÃÇij¸öÒ³ÃæÐèÒªÒ»¸öÓû§ÁÐ±í£¬¶ø²»½ö½öÊÇÒ»¸öµ¥Ò»µÄÓû§ÐÅÏ¢£¬ÄÇôÕâÀï¾ÍÐèÒª´´½¨Ò»¸öÓû§ÁбíÊý×é¡£
ÏÂÃæ´úÂëÑÝʾÁËʹÓÃJSONÐÎʽ¶¨ÒåÕâ¸öÓû§ÁÐ±í£º
[
{"UserID":11, "Name":{"FirstName":"Truly","LastName":"Zhu"}, "Email":"zhuleipro¡òhotmail.com"},
{"UserID":12, "Name":{"FirstName":"Jeffrey","LastName":"Richter"}, "Email":"xxx¡òxxx.com"},
{"UserID":13, "Name":{"FirstName":"Scott","LastName":"Gu"}, "Email":"xxx2¡òxxx2.com"}
]


Ïà¹ØÎĵµ£º

Javascript ¼¼Çɼ¯ºÏ(ºÜºÃ)

   
ʼþÔ´¶ÔÏó
event.srcElement.tagName
event.srcElement.type
²¶»ñÊÍ·Å
event.srcElement.setCapture(); 
event.srcElement.releaseCapture(); 
ʼþ°´¼ü
event.keyCode
event.shiftKey
event.altKey
event.ctrlKey
ʼþ·µ»ØÖµ
event.returnValue
Êó±êλÖÃ
eve ......

¿ªÆôJavaScriptµ÷ÊÔ

ÏÂÃæµÄ²Ù×÷²½ÖèÃèÊöÁËÔõÑùÀûÓÃvs.netÖеĵ÷ÊÔÆ÷À´µ÷ÊÔjavascript£º
1,Ê×ÏÈ£¬ÒªÈÃÄãµÄieÔÊÐíµ÷ÊԽű¾£¬¾ßÌå²½ÖèÈçÏÂ:
   ´ò¿ªie->¹¤¾ß²Ëµ¥->interÑ¡Ïî->¸ß¼¶Ñ¡Ï->È¥µô“½ûÖ¹½Å±¾µ÷ÊÔ"Ñ¡Ïî
2,´ò¿ªvs.net,´´½¨Ò»¸öеÄasp.netÏîÄ¿(»ò´ò¿ªÒ»¸ö)
3,ÔËÐÐÄãÒªµ÷ÊÔµÄÒ³Ãæ
4,µ±ÄãµÄÒ³Ãæ³ÊÏÖÔÚieÀ ......

JavaScript£¨JS£©×Ô´ø×Ö·û´®´¦Àíº¯Êý


concat
½«Á½¸ö»ò¶à¸ö×Ö·ûµÄÎı¾×éºÏÆðÀ´£¬·µ»ØÒ»¸öеÄ×Ö·û´®¡£
var a = "hello";
var b = ",world";
var c = a.concat(b);
alert(c);
//c = "hello,world"
indexOf
·µ»Ø×Ö·û´®ÖÐÒ»¸ö×Ó´®µÚÒ»´¦³öÏÖµÄË÷Òý£¨´Ó×óµ½ÓÒËÑË÷£©¡£Èç¹ûûÓÐÆ¥ÅäÏ·µ»Ø -1 ¡£
var index1 = a.indexOf(& ......

href="javascript:void(0);"ÔÚIE6Öн«¶ÏÒì²½ÇëÇó

HtmlÒ³
<a href="javascript:void(0);" mce_href="javascript:void(0);" ><img id="SubmitFeedback" src="/images/comment_btn.gif" mce_src="images/comment_btn.gif" /></a>
½Å±¾
$(document).ready(function() {
alert("Ò³ÃæË¢ÐÂ&q ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ