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

Javascript Ö®prototypeÊôÐÔ

ÔÚjsÖУ¬Ã¿¸ö¶ÔÏó¶¼ÓÐÒ»¸öprototypeÊôÐÔ£º·µ»Ø¶ÔÏóÀàÐÍÔ­Ð͵ÄÒýÓ᣺ÜÞÖ¿Ú£¡Ï°Óï“ÒÀºù«»­Æ°”£¬ÕâÀïµÄºù«¾ÍÊÇÔ­ÐÍ£¬ÄÇô“ư.prototype” ·µ»ØµÄ¾ÍÊǺù«£¬»òÕߓư.prototype= new ºù«()”¡£
prototypeµÄÓÃ;£º
¼Ì³Ð
ÓÐÒ»¸ö¶ÔÏó£­£­×ÓÀࣺ
function ×ÓÀà() {
this.lastname = "Samuel";
}
ÓÐÒ»¸ö¶ÔÏó£­£­¸¸Àࣺ
function ¸¸Àà() {
this.firstname = "Shen";
}
ÏÖÔÚ×ÓÀàÊÇÓÐÃûÎÞÐÕ£¬¸¸ÀàÊÇÓÐÐÕÎÞÃû£¬Èç¹û×ÓÀàÒªÓÐÃûÓÐÐյϰ£¬Ö»ÒªËµÃ÷£­£­×ÓÀàµÄÔ­ÐÍÊǸ¸À࣭£­¾Í¿ÉÒÔÁË£¬¼´×ÓÀà¼Ì³Ð×Ô¸¸Àࣺ
×ÓÀà.prototype = new ¸¸Àà();
ÖÁ´Ë£¬×ÓÀà¾Í²»ÔÙÊÇÓÐÃûÎÞÐÕÁË¡£
alert(×ÓÀà.firstname + " " + ×ÓÀà.lastname); //Samuel Shen
Ç£Ò»·¢¶ø¶¯È«Éí
¼ÈÈ»prototype·µ»ØµÄÊÇÔ­Ð͵ÄÒýÓã¬ÄÇôÈç¹û¸Ä±äÔ­Ð͵ϰ£¬ËùÓм̳Ð×Ô¸ÃÔ­Ð͵ĶÔÏó¶¼½«Êܵ½Ó°Ïì¡£
function Point(x,y) {
this.x = x;
this.y = y;
}
var p1 = new Point(1,2);
var p2 = new Point(3,4);
Point.prototype.z = 0; //¶¯Ì¬ÎªPointµÄÔ­ÐÍÌí¼ÓÁËÊôÐÔ
alert(p1.z); //0
alert(p2.z); //0
/***************************************************************************/
function Person(name,sex) { //PersonÀàµÄ¹¹Ô캯Êý
this.name = name;
this.sex = sex;
}
Person.prototype.age = 12; //ΪPersonÀàµÄprototypeÊôÐÔ¶ÔÓ¦µÄprototype¶ÔÏóµÄÊôÐÔ¸³Öµ,
//Ï൱ÓÚΪPersonÀàµÄ¸¸ÀàÌí¼ÓÊôÐÔ
Person.prototype.print = function() { //ΪPersonÀàµÄ¸¸ÀàÌí¼Ó·½·¨
alert(this.name+"_"+this.sex+"_"+this.age);
};

var p1 = new Person("name1","male"); //p1µÄageÊôÐԼ̳Ð×ÓPersonÀàµÄ¸¸Àà(¼´prototype¶ÔÏó)
var p2 = new Person("name2","male");

p1.print(); //name1_male_12
p2.print(); //name2_male_12

p1.age = 34; //¸Ä±äp1ʵÀýµÄageÊôÐÔ p1ÊôÐÔÔÚ²»Ö¸ÏòPersonµÄprototypeÊôÐÔ
p1.print(); //name1_male_34
p2.print(); //name2_male_12

Person.prototype.age = 22; //¸Ä±äPersonÀàµÄ³¬ÀàµÄageÊôÐÔ
p1.print(); //name1_male_34(p1µÄageÊôÐÔ²¢


Ïà¹ØÎĵµ£º

Javascript»ñÈ¡¸÷ÖÖä¯ÀÀÆ÷¿É¼û´°¿Ú´óС

¸ãÁË´ó°ëÌ죬×ÜËãŪÃ÷°×ÁËΪºÎÓÃdocument.body.clientHeight£¬document.body.offsetHeight¶¼Ã»Óаì
·¨»ñÈ¡ÍøÒ³¿É¼ûÇøÓòµÄÕýÈ·Öµ£¬Ô­À´×ï¿ý»öÊ×ÊÇW3C¶¨ÒåµÄ±ê×¼£¡£¡ÔÚж¨Òå³öÀ´µÄ±ê×¼ÏÂ
document.documentElement.clientHeightÔÚIEºÍ»ðºüÀï¶¼ÄÜ»ñÈ¡ÕýÈ·Öµ£¬ÏÂÃæÒ»ÆªÎÄÕÂÏêϸ½éÉÜÁË»ñÈ¡¸÷ÖÖä¯ÀÀÆ÷¿É¼û
´°¿Ú´óСÕâ·½ÃæµÄ²î ......

javascriptÖеÄmoveStartºÍmoveEnd·½·¨

Ïê̽TextRange¶ÔÏó--²éÕÒÓëÑ¡Ôñ
TextRange¶ÔÏóÊǶ¯Ì¬HTML(DHTML)µÄ¸ß¼¶ÌØÐÔ£¬Ê¹ÓÃËü¿ÉÒÔʵÏֺܶàºÍÎı¾ÓйصÄÈÎÎñ£¬ÀýÈçËÑË÷ºÍÑ¡ÔñÎı¾¡£Îı¾·¶Î§ÈÃÄú¿ÉÒÔÑ¡ÔñÐԵĽ«×Ö·û¡¢µ¥´ÊºÍ¾ä×Ó´ÓÎĵµÖÐÌôÑ¡³öÀ´¡£TextRange¶ÔÏóÊÇÔÚHTMLÎĵµ½«ÒªÏÔʾµÄÎı¾Á÷ÉϽ¨Á¢¿ªÊ¼ºÍ½áÊøÎ»ÖõijéÏó¶ÔÏó¡£
ÏÂÃæÊÇTextRangeµÄ³£ÓÃÊôÐÔÓë·½·¨£º
Ê ......

javascript»ñµÃÊó±êµÄ¾ø¶ÔλÖÃ

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name=" ......

javascript DateÈÕÆÚ¶ÔÏó (ת)

´´½¨Ò»¸öÈÕÆÚ¶ÔÏó£º
var objDate=new Date([arguments list]);
²ÎÊýÐÎʽÓÐÒÔÏ£µÖÖ£º
   new Date("month dd,yyyy hh:mm:ss");
   new  Date("month dd,yyyy");
   new  Date(yyyy,mth,dd,hh,mm,ss);
   new Date(yyyy,mth,dd);
   new Date(ms); ......

javascript:void(0)

  javascript:void(0)
   ¸Õ¿ªÊ¼¶¼²»ÖªµÀÊÇɶÒâ˼
  Æäʵ¾ÍÊÇÒ»¸öËÀÁ´½Ó£¬Ê²Ã´ÊÂÇé¶¼²»×ö¡£
  <a id="link_${user.account}" href="javascript:void(0);" onclick="changSubmit();" style="cursor:pointer;height:25px;width:60px;margin-top:10px;">·¢ËÍemail</a>
  Õâ¾ä ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ