JavaScript£ºprototypeÊôÐÔʹÓÃ˵Ã÷
prototype ÊÇÔÚ IE 4 ¼°ÆäÒÔºó°æ±¾ÒýÈëµÄÒ»¸öÕë¶ÔÓÚijһÀàµÄ¶ÔÏóµÄ·½·¨£¬¶øÇÒÌØÊâµÄµØ·½±ãÔÚÓÚ£ºËüÊÇÒ»¸ö¸øÀàµÄ¶ÔÏóÌí¼Ó·½·¨µÄ·½·¨£¡ÕâÒ»µã¿ÉÄÜÌýÆðÀ´»áÓеãÂÒ£¬±ð¼±£¬ÏÂÃæÎÒ±ãͨ¹ýʵÀý¶ÔÕâÒ»ÌØÊâµÄ·½·¨×÷ÒÑϽ²½â£º
¡¡¡¡Ê×ÏÈ£¬ÎÒÃÇÒªÏÈÁ˽âÒ»ÏÂÀàµÄ¸ÅÄJavaScript ±¾ÉíÊÇÒ»ÖÖÃæÏò¶ÔÏóµÄÓïÑÔ£¬ËüËùÉæ¼°µÄÔªËظù¾ÝÆäÊôÐԵIJ»Í¬¶¼ÒÀ¸½ÓÚijһ¸öÌض¨µÄÀà¡£ÎÒÃÇËù³£¼ûµÄÀà°üÀ¨£ºÊý×é±äÁ¿(Array)¡¢Âß¼±äÁ¿(Boolean)¡¢ÈÕÆÚ±äÁ¿(Date)¡¢½á¹¹±äÁ¿(Function)¡¢ÊýÖµ±äÁ¿(Number)¡¢¶ÔÏó±äÁ¿(Object)¡¢×Ö·û´®±äÁ¿(String) µÈ£¬¶øÏà¹ØµÄÀàµÄ·½·¨£¬Ò²ÊdzÌÐòÔ±¾³£Óõ½µÄ£¨ÔÚÕâÀïÒªÇø·ÖÒ»ÏÂÀàµÄ×¢ÒâºÍÊôÐÔ·¢·½·¨£©£¬ÀýÈçÊý×éµÄpush·½·¨¡¢ÈÕÆÚµÄgetϵÁз½·¨¡¢×Ö·û´®µÄsplit·½·¨µÈµÈ£¬
¡¡¡¡µ«ÊÇÔÚʵ¼ÊµÄ±à³Ì¹ý³ÌÖв»ÖªµÀÓÐûÓиоõµ½ÏÖÓз½·¨µÄ²»×㣿prototype ·½·¨Ó¦Ô˶øÉú£¡ÏÂÃ棬½«Í¨¹ýʵÀýÓÉdzÈëÉî½²½â prototype µÄ¾ßÌåʹÓ÷½·¨£º
1¡¢×î¼òµ¥µÄÀý×Ó£¬Á˽â prototype£º
(1) Number.add(num)£º×÷Óã¬Êý×ÖÏà¼Ó
ʵÏÖ·½·¨£ºNumber.prototype.add = function(num){return(this+num);}
ÊÔÑ飺alert((3).add(15)) -> ÏÔʾ 18
(2) Boolean.rev(): ×÷Ó㬲¼¶û±äÁ¿È¡·´
ʵÏÖ·½·¨£ºBoolean.prototype.rev = function(){return(!this);}
ÊÔÑ飺alert((true).rev()) -> ÏÔʾ false
ÊDz»ÊǺܼòµ¥£¿ÕâÒ»½Ú½ö½öÊǸæË߶ÁÕßÓÖÕâôһÖÖ·½·¨£¬ÕâÖÖ·½·¨ÊÇÕâÑùÔËÓõġ£
2¡¢ÒÑÓз½·¨µÄʵÏÖºÍÔöÇ¿£¬³õʶ prototype£º
(1) Array.push(new_element)
¡¡¡¡×÷ÓãºÔÚÊý×éĩβ¼ÓÈëÒ»¸öеÄÔªËØ
¡¡¡¡ÊµÏÖ·½·¨£º
¡¡¡¡Array.prototype.push = function(new_element){
this[this.length]=new_element;
return this.length;
}
¡¡¡¡ÈÃÎÒÃǽøÒ»²½À´ÔöÇ¿Ëû£¬ÈÃËû¿ÉÒÔÒ»´ÎÔö¼Ó¶à¸öÔªËØ£¡
¡¡¡¡ÊµÏÖ·½·¨£º
¡¡¡¡Array.prototype.pushPro = function() {
var currentLength = this.length;
for (var i = 0; i < arguments.length; i++) {
this[currentLength + i] = arguments[i];
}
&nb
Ïà¹ØÎĵµ£º
Javascriptº¯Êý°üº¬Ò»¸öαÊý×飨pseudo-array£©£¬¸ÃÊý×é°üº¬ËùÓд«Èë²ÎÊý£¬ÎÒÃDz»ÄÜÐÞ¸ÄËü£¬µ«¿ÉÒÔ·ÃÎÊÆäÖеijÉÔ±£¬¸ÃÊý×éÒ²¾ßÓÐlengthÊôÐÔ¡£
º¯ÊýÖØÔØÒÀÀµÓÚÅжϴ«Èë²ÎÊý¸öÊýºÍÀàÐ͵ÄÄÜÁ¦¡£
º¯ÊýÖØÔصÄÀý×Ó£º
<html>
<head>
<mce:script type="text/javascript"><!--
function sendMessage(msg ......
JavaScriptÖеÄ5ÖÖʼþʹÓ÷½Ê½½â˵(ת)
Ϊ×é¼þÌṩʼþ´¦ÀíÈë¿Ú£¬¿ÉÒÔ¼«´óµÄÌá¸ß×é¼þµÄ·â±ÕÐÔ£¬Í¬Ê±ÓÖÄÜÈÃ×é¼þºÜºÃµÄºÍÍâ½çͨÐÅ¡£²¢ÇÒÕâÒ²ÊÇÎÒÃÇÒѾϰ¹ßʹÓõÄÒ»ÖÖ¿ª·¢Ä£Ê½£¬.NET¡¢DHTMLµÈ¶¼ÌṩÁËÒ»Ì×ÍêÕûµÄʼþ´¦ÀíÄ£ÐÍ¡£ÏÂÃæÊǹØÓÚʹÓÃDHTMLÖÐʼþµÄÒ»¸ö×ܽᡣ
DHTMLÌṩÁË3ÖÖʼþµÄÊ¹Ó ......
×Ô¼ºÔÚ¿ª·¢ÖÐÅöµ½µÄ+ÁËһЩÔÚÍøÉÏËѵ½µÄ¡£¡£ºÍ´ó¼Ò·ÖÏíÏ¡£
DropdownlistÎÞˢеÄÀý×Ó¡£xml.
ÀýÈçÎı¾ÑéÖ¤!
ÏÂÃæÊÇÒ»¸öµ¥Ñ¡°´Å¦Ç°Ì¨²»Ë¢ÐµÄÀý×Ó.ÓкõľÍÍùÉÏÌù
<mce:script language="javascript"><!--
function SetButton()
{
if(document.all.rdoByHuman.checked==true)
{
......
JavaScript¾ÍÕâô»ØÊÂ1£º»ù´¡ÖªÊ¶
1 ´´½¨½Å±¾¿é
1: <script language=”JavaScript”>
2: JavaScript code goes here
3: </script>
2 Òþ²Ø½Å±¾´úÂë
1: <script language=”JavaScript”>
2: <!--
3: document.write(“Hello”);
4: // -->
5: </script ......
JavaScriptÀï×Ö·û´®ÀàÐÍת»»³ÉÈÕÆÚÀàÐÍ£º
Èç¹û×Ö·û´®ÖÐÓпոñ»òÊÇÆäËû·Ö¸î·û·Ö¸î£¬¿ÉÒÔÓÃsplit·½·¨ÏȲð·Ö£¬·µ»ØÒ»¸öÊý×飬ÔÙ°ÑÕâ¸öÊý×éÀïµÄÄêÔÂÈÕ×÷Ϊ²ÎÊý´«µ½new Date()ÀïÉú³ÉÈÕÆÚÀàÐÍ£»
Èç¹ýûÓÐÌØÊâ·Ö¸ô·û£¬¿ÉÒÔÓÃsubstr£¨x£¬y£©·½·¨À´È¡×Ó×Ö·û´®À´Éú³ÉÈÕÆÚ£¬substr£¨x£¬y£©Àx±íʾȡ×Ö´®µÄ¿ªÊ¼Î»Öã¬y±íʾ×Ó´®µÄ³ ......