×òÌ죬ÎÒ±¾À´´òË㣬°ÑÕâ¸ö»°Ìâ½áÊøÁË¡£
µ«ÊÇ£¬Ð´µ½Ò»°ëµÄʱºò£¬ÎÒͻȻÒâʶµ½£¬JavascriptµÄ¼Ì³ÐÓÐÁ½ÖÖ¡£Ò»ÖÖÊÇ»ùÓÚ"º¯Êý¶ÔÏó"µÄ¼Ì³Ð£¬Ò²¾ÍÊÇÒ»¸öfunctionÈ¥¼Ì³ÐÁíÍâÒ»¸öfunction£¬Õâ¸öÎÒÒѾÔÚ×òÌì½éÉܹýÁË¡£
ÁíÒ»ÖÖÔòÊÇ»ùÓÚ"·Çº¯Êý¶ÔÏó"µÄ¼Ì³Ð£¬²»Éæ¼°function¡£ËüµÄ×ö·¨ÓëÇ°Ò»ÖÖÇé¿öÍêÈ«²»Í¬¡£
Ò»¡¢Ê²Ã´ÊÇ"·Çº¯Êý¶ÔÏó"µÄ¼Ì³Ð£¿
±ÈÈ磬ÏÖÔÚÓÐÒ»¸ö¶ÔÏ󣬽Ð×ö"ÖйúÈË"¡£
¡¡¡¡var Chinese = {
¡¡¡¡¡¡¡¡nation:'Öйú'
¡¡¡¡};
»¹ÓÐÒ»¸ö¶ÔÏ󣬽Ð×ö"Ò½Éú"¡£
¡¡¡¡var Doctor ={
¡¡¡¡¡¡¡¡career:'Ò½Éú'
¡¡¡¡}
ÇëÎÊ£¬ÎÒÔõÑù²ÅÄÜÈÃ"Ò½Éú"È¥¼Ì³Ð"ÖйúÈË"£¬Ò²¾ÍÊÇ˵£¬ÎÒÔõÑù²ÅÄÜÉú³ÉÒ»¸ö"ÖйúÒ½Éú"µÄ¶ÔÏó£¿
¶þ¡¢object()·½·¨
json¸ñʽµÄ·¢Ã÷ÈËDouglas Crockford£¬Ìá³öÁËÒ»¸öobject()º¯Êý£¬¿ÉÒÔ×öµ½ÕâÒ»µã¡£
¡¡¡¡function object(o) {
¡¡¡¡¡¡¡¡function F() {}
¡¡¡¡¡¡¡¡F.prototype = o;
¡¡¡¡¡¡¡¡return new F();
¡¡¡¡}
Õâ¸öobject()º¯Êý£¬Æäʵֻ×öÒ»¼þÊ£¬¾ÍÊÇ°Ñ×Ó¶ÔÏóµÄprototypeÊôÐÔ£¬Ö¸Ïò¸¸¶ÔÏ󣬴ӶøʹµÃ×Ó¶ÔÏóÓ븸¶ÔÏóÁ¬ÔÚÒ»Æð¡£
ʹÓõÄʱºò£¬µÚÒ»²½ÏÈÔÚ¸¸¶ÔÏóµÄ»ù´¡ÉÏ£¬Éú³É×Ó¶ÔÏó£º
¡¡¡¡var Doctor = object(Chinese);
È»ºó£¬ÔÙ¼ÓÉÏ×Ó¶ÔÏó±¾ÉíµÄÊôÐÔ£ ......
ѧϰJavascript£¬×îÄѵĵط½ÊÇʲô£¿
ÎÒ¾õµÃ£¬Object£¨¶ÔÏó£©×îÄÑ¡£ÒòΪJavascriptµÄObjectÄ£ÐͺܶÀÌØ£¬ºÍÆäËûÓïÑÔ¶¼²»Ò»Ñù£¬³õѧÕß²»ÈÝÒ×ÕÆÎÕ¡£
ÏÂÃæ¾ÍÊÇÎÒµÄѧϰ±Ê¼Ç£¬Ï£Íû¶Ô´ó¼ÒѧϰÕâ¸ö²¿·ÖÓÐËù°ïÖú¡£ÎÒÖ÷Òª²Î¿¼ÁËObject-Oriented JavaScriptºÍProfessional JavaScript for Web Developers (2nd Edition)ÕâÁ½±¾Êé¡£ËüÃǶ¼ÊǷdz£ÓÅÐãµÄJavascript¶ÁÎÍƼöÔĶÁ¡£
±Ê¼Ç·Ö³ÉÁ½²¿·Ö¡£½ñÌìµÄµÚÒ»²¿·ÖÊÇÌÖÂÛ"·â×°"£¨Encapsulation£©£¬ÏÂÒ»´ÎµÄµÚ¶þ²¿·ÖÌÖÂÛ"¼Ì³Ð"£¨Inheritance£©¡£
============================
Javascript ÃæÏò¶ÔÏó±à³Ì£¨Ò»£©£º·â×°
×÷ÕߣºÈîÒ»·å
JavascriptÊÇÒ»ÖÖ»ùÓÚ¶ÔÏó£¨object-based£©µÄÓïÑÔ£¬ÄãÓöµ½µÄËùÓж«Î÷¼¸ºõ¶¼ÊǶÔÏó¡£µ«ÊÇ£¬ËüÓÖ²»ÊÇÒ»ÖÖÕæÕýµÄÃæÏò¶ÔÏó±à³Ì£¨OOP£©ÓïÑÔ£¬ÒòΪËüµÄÓï·¨ÖÐûÓÐclass£¨Àࣩ¡£
ÄÇô£¬Èç¹ûÎÒÃÇÒª°Ñ"ÊôÐÔ"£¨property£©ºÍ"·½·¨"£¨method£©£¬·â×°³ÉÒ»¸ö¶ÔÏó£¬ÉõÖÁÒª´ÓÔÐͶÔÏóÉú³ÉÒ»¸öʵÀý¶ÔÏó£¬ÎÒÃÇÓ¦¸ÃÔõô×öÄØ£¿
1. Éú³É¶ÔÏóµÄÔʼģʽ
¼Ù¶¨ÎÒÃÇ°Ñè¿´³ÉÒ»¸ö¶ÔÏó£¬ËüÓÐ"Ãû×Ö"ºÍ"ÑÕÉ«"Á½¸öÊôÐÔ¡£
¡¡¡¡var Cat = {
¡¡¡¡¡¡¡¡name : '',
¡¡¡¡¡¡¡¡color : ''
¡¡¡¡}
ÏÖÔÚ£¬ÎÒÃÇÐèÒª¸ù¾ÝÕâ¸öÔÐͶÔÏó£¬Éú³ÉÁ ......
×î½ü±àдJavascript´úÂë¡£Æð³õû¹ÜÄÇô¶à¡£Ò»Õó¿ñд¡£´úÂëдµÃ²î²»¶àÁË¡£½á¹ûÉÏ°ÙKÎļþ¼¸Ê®¸ö¡£µ±È» û°ì·¨ÐèҪѹËõÁË¡£ÎªÁËËٶȡ£
ÕÒѹËõ¹¤¾ß¡£ÅªÁËÏ¡£½á¹û´íÎóÒ»´ó¶Ñ¡£×îºó²Å·¢ÏÖÊÇ×Ô¼ºÐ´µÄ´úÂë²»¹æ·¶µ¼Öµġ£¼ì²éÁË°ëÌìÐÞÕýÁ˼¸Ê®¸öµØ·½¡£ÖÕÓÚÄÜѹËõÁË¡£
ÏÂÃæ×ܽáÏÂÐèҪעÒâµÄµØ·½
1¡¢¶ÔÏó½áβ function½áβ ×îºÃÒª¼Ó ";"ºÅ
Èç
var a={
.....
};
2¡¢Êý×é½áβҪ¼Ó ";" ºÅ¡£
È磺
var b=[...];
3¡¢º¯Êý½áβҪ¼Ó ";" ºÅ¡£
È磺
func1();
4¡¢»¨À¨ºÅÄÚ ×îºóÒ»¸öÓï¾ä¿ÉÒÔ²»¼Ó ";" ºÅ¡£
5¡¢ifÓï¾äµÄ·ÖÖ§ ×îºÃ¶¼Óà "{"¡¢"}"À¨ÆðÀ´¡£ ......
phpÖеÄevalºÍJavaScriptÖеÄevalÇø±ð£º
Definition and Usage
¶¨ÒåºÍÓ÷¨
The eval() function evaluates a
string as PHP code.
eval()º¯ÊýµÄ×÷ÓÃÊÇ£º·µ»ØÓëPHP´úÂëÏà¶ÔÓ¦µÄ×Ö·û´®¡£
The string
must be valid PHP code and must end with semicolon.
Õâ¸ö×Ö·û´®±ØÐëÊÇÓÐЧµÄPHP´úÂ룬
²¢ÇÒ±ØÐëÒԷֺŽáÊø¡£
This function returns NULL unless a return statement is
called in the code string. Then the value passed to return is returned.
If there is a parse error in the code string, eval() returns FALSE.
³ý
ÁËÔÚ´úÂë×Ö·û´®ÖÐÇëÇó“·µ»ØÓï¾ä[return
statement]”µÄÇé¿ö£¬ÔÚÆäËüÇé¿öÏ£¬Õâ¸öº¯Êý¶¼½«·µ»Ø¿ÕÖµ[NULL]£»Èç¹ûÇëÇóÁË“·µ»ØÓï¾ä”£¬ÄÇôËü½«·µ»Ø±»´«µÝµ½“·µ»ØÓï¾ä”ÖеÄÖµ¡£Èç
¹ûÕâ¶Î´úÂë×Ö·û´®³öÏÖ´íÎó£¬eval()º¯Êý½«·µ»ØFalse¡£
eval()º¯Êý£¬Õâ¸öº¯Êý¿ÉÒÔ°ÑÒ»¸ö×Ö·û´®µ±×÷Ò»¸öJavaScript±í´ïʽһÑùÈ¥Ö´ÐÐËü¡£
¿ÉÒÔ½«×Ö·û´®µÄÐÎʽת»»³ÉÊýÖµÐ͵È
ob_start() ob_end_clean() ob_get_contents()
(2008-12-19 16:17:41)
תÔØ
±êÇ©£º
»º³åÇø
start
±äÁ¿
work
ob_sta ......
phpÖеÄevalºÍJavaScriptÖеÄevalÇø±ð£º
Definition and Usage
¶¨ÒåºÍÓ÷¨
The eval() function evaluates a
string as PHP code.
eval()º¯ÊýµÄ×÷ÓÃÊÇ£º·µ»ØÓëPHP´úÂëÏà¶ÔÓ¦µÄ×Ö·û´®¡£
The string
must be valid PHP code and must end with semicolon.
Õâ¸ö×Ö·û´®±ØÐëÊÇÓÐЧµÄPHP´úÂ룬
²¢ÇÒ±ØÐëÒԷֺŽáÊø¡£
This function returns NULL unless a return statement is
called in the code string. Then the value passed to return is returned.
If there is a parse error in the code string, eval() returns FALSE.
³ý
ÁËÔÚ´úÂë×Ö·û´®ÖÐÇëÇó“·µ»ØÓï¾ä[return
statement]”µÄÇé¿ö£¬ÔÚÆäËüÇé¿öÏ£¬Õâ¸öº¯Êý¶¼½«·µ»Ø¿ÕÖµ[NULL]£»Èç¹ûÇëÇóÁË“·µ»ØÓï¾ä”£¬ÄÇôËü½«·µ»Ø±»´«µÝµ½“·µ»ØÓï¾ä”ÖеÄÖµ¡£Èç
¹ûÕâ¶Î´úÂë×Ö·û´®³öÏÖ´íÎó£¬eval()º¯Êý½«·µ»ØFalse¡£
eval()º¯Êý£¬Õâ¸öº¯Êý¿ÉÒÔ°ÑÒ»¸ö×Ö·û´®µ±×÷Ò»¸öJavaScript±í´ïʽһÑùÈ¥Ö´ÐÐËü¡£
¿ÉÒÔ½«×Ö·û´®µÄÐÎʽת»»³ÉÊýÖµÐ͵È
ob_start() ob_end_clean() ob_get_contents()
(2008-12-19 16:17:41)
תÔØ
±êÇ©£º
»º³åÇø
start
±äÁ¿
work
ob_sta ......
// µ÷ÓÃÒ³ÃæµÄˢз½·¨
IHTMLWindow2* pWindow;
IHTMLDocument2* pDocument;
HRESULT hr = GetDHtmlDocument(&pDocument);
hr = pDocument->get_parentWindow(&pWindow);
if( pWindow)
{
VARIANT ret;
ret.vt = VT_EMPTY;
CString sFunc = _T("RefreshFileForClient()");
CString sLang = _T("javascript");
hr = pWindow->execScript(sFunc.AllocSysString(), sLang.AllocSysString(), &ret);
} ......
ÔÚWeb¿ª·¢ÖУ¬»áÓöµ½´ÓÒ»Ò³£¨¸¸Ò³£©µ¼ÏòÁíÒ»Ò³£¨×ÓÒ³£©£¬²¢ÇÒÒªÇó“·µ»Ø”¸¸Ò³µÄÇé¿ö£¬ÔÚÕâÀïÈç¹ûÓÃASP.NETÌṩµÄ Response.Redirect()·½·¨£¬ÍùÍù²»»á´ïµ½ÀíÏëµÄЧ¹û£¬ÀýÈ磺·µ»Øºó£¬ÖØмÓÔØÁËÒ³Ã棬ÎÞ·¨±£´æµ¼Ïò×ÓҳǰµÄ״̬£¬µÈµÈ£¬ÔÚÕâÀïÎҾͽéÉÜ Ò»ÏÂÈçºÎʹÓÃJavaScriptÖÐhistory.go()º¯ÊýÀ´ÊµÏÖ·µ»Ø¹¦Äܲ¢ÇÒ±£´æס״̬µÄ·½·¨¡£
Õâ¸öº¯ÊýÓÃÆðÀ´ºÜ¼òµ¥£¬Ö»ÒªÔÚÒ³ÃæÉϼÓÒ»¸öhtmlµÄinputÔªËØ£¬ÀýÈ磺
<input type="button" value="·µ»Ø">
È»ºóÔÙΪÕâ¸öÔªËØÌí¼ÓonclickÊôÐÔ£¬È磺
<input type="button" value="·µ»Ø" onclick="history.go(-1);">
ÕâÑù¾ÍÄÜ´ïµ½·µ»ØÉÏÒ»Ò³µÄЧ¹û¡£µ«ÊÇ£¬ÍùÍùÔÚʵ¼ùÖУ¬²¢Ã»ÓÐÕâô¼òµ¥£¬µ±ÄãÔÚÏò·þÎñÆ÷Ìá½»ÇëÇóµÄʱºò£¬ÒýÆðÒ³Ãæ»Ø·¢£¬ÄãÔÙÓÃhistory.go(-1) ÕâÕоͲ»ÁéÀ²£¬ËüÔÚÕâÀïÊÇ·µ»ØÄã»Ø·¢Ç°µÄ״̬£¬goºóÃæµÄ²ÎÊý£¬Êµ¼ÊÉϾÍÊDZêʶÄãÒª·µ»ØÄã»Ø·¢µÚÇ°n´ÎµÄ״̬£¬ËùÒÔÖ»ÒªÄܼÇס»Ø·¢Á˼¸´Î£¬¾ÍÄÜÓà history.go(-n)׼ȷµØ·µ»Øµ½¸¸Ò³ÁË¡£
Ô ......