¡¶Îò͸javascript¡·Ñ§Ï°±Ê¼Ç£º¾Å¡¢ÔÐͱ϶
ÒýÑÔ
prototypeÔ´×Ô·¨ÓÈí¼þ½çµÄ±ê×¼·ÒëΪ“ÔÐÍ”£¬´ú±íÊÂÎïµÄ³õʼÐÎ̬£¬Ò²º¬ÓÐÄ£ÐͺÍÑù°åµÄÒâÒå¡£
prototypeÊôÐÔ
JavaScriptµÄËùÓÐfunctionÀàÐ͵ĶÔÏó¶¼ÓÐÒ»¸öprototypeÊôÐÔ¡£Õâ¸öprototypeÊôÐÔ±¾ÉíÓÖÊÇÒ»¸ö object ÀàÐ͵ĶÔÏó£¬Òò´ËÎÒÃÇÒ²¿ÉÒÔ¸øÕâ¸ö prototype ¶ÔÏóÌí¼ÓÈÎÒâµÄÊôÐԺͷ½·¨¡£¼ÈÈ» prototypeÊǶÔÏóµÄ“ÔÐÍ”£¬ÄÇôÓɸú¯Êý¹¹Ôì³öÀ´µÄ¶ÔÏóÓ¦¸Ã¶¼»á¾ßÓÐÕâ¸ö“ÔÐÍ”µÄÌØÐÔ¡£ÊÂʵÉÏ£¬ÔÚ¹¹Ô캯ÊýµÄprototypeÉ϶¨ÒåµÄËùÓÐÊôÐԺͷ½·¨£¬¶¼ÊÇ¿ÉÒÔͨ¹ýÆä¹¹ÔìµÄ¶ÔÏóÖ±½Ó·ÃÎʺ͵÷Óõġ£Ò²¿ÉÒÔÕâô˵£¬prototypeÌṩÁËһȺͬÀà¶ÔÏó¹²ÏíÊôÐԺͷ½·¨µÄ»úÖÆ¡£ÔËÐÐÈçÏ´úÂ룬Ȼºó¹Û²ì¡£
<script language="javascript">
function person(name){ //¹¹Ô캯Êýperson
this.name = name;
//this´´½¨³öµÄ¶ÔÏó£¬Ã¿Ò»¸ö¸±±¾¶¼»á°üº¬ÆäÊôÐԺͺ¯Êý
this.say = function(){alert("hello, i'm " + this.name);}
}
//prototype´´½¨µÄº¯Êý¶ÔÏó£¬ËùÓеĸ±±¾¹²Ïíͬһ¸öº¯Êý
person.prototype.show = function(){alert("hi~~, i'm " + this.name);}
var p1 = new person("p1");
var p2 = new person("p2");
alert(p1.say == p2.say); //false£¬Ã»¹²Ïíº¯Êý
alert(p1.show == p2.show); //true£¬¹²Ïíº¯Êý
</script>
ÔÐÍÁ´
<script language="javascript">
function person(name){
this.name = name;
}
person.prototype.say = function(){alert("hello, i'm " + this.name);}
function employee(name, salary){
//µ÷ÓÃperson×÷ΪemployeeµÄ¹¹Ô캯Êý——ÖØµã
person.call(this, name); //Ä¿µÄÊǼ̳ÐpersonµÄÊôÐÔ
this.salary = salary;
}
//×ÓÀ๹Ô캯ÊýÊ×ÏÈÐèÒªÓÃÉϲ㹹Ô캯ÊýÀ´½¨Á¢ prototype¶ÔÏó£¬ÊµÏּ̳еĸÅÄî——ÖØµã
employee.prototype = new person(); //Ä¿µÄÊǼ̳ÐpersonµÄ·½·¨£¬Ö»ÐèÒªÆä prototype µÄ·½·¨£¬´Ë¶ÔÏóµÄ³ÉԱûÓÐÈκÎÒâÒ壡
employee.prototype.showMoney = function(){alert(this.name + "'s salary is " + this.salary);}
var bill = new pers
Ïà¹ØÎĵµ£º
ʵÏÖ¿¨Ò³Ê½webµÄjs£º
function ShowContent(id,num){
for(i=1;i<=num;i++){
document.getElementById("page_"+i).className="";
document.getElementById("content_"+i).style.display="none";
}
document.getElementById("content_"+id).style.display="block";
......
//ͳ¼Æ×Ö·û´®ÖÐÌØ¶¨×Ö·û´®µÄ¸öÊý
function getStrCount(scrstr,armstr)
{ //scrstr Ô´×Ö·û´® armstr ÌØÊâ×Ö·û
var count=0;
while(scrstr.indexOf(armstr) >=1 )
{
scrstr = scrstr.replace(armstr,"")
count++;
}
re ......
¿ª·¢Ê±£¬ÐèÒªÓõ½µÄJavaScript½ø¶ÈÌõ~~~
<style type="text/css">
#out {
width:200px;
height:16px !important;
border:1px solid #5858D1;
text-align:center;
position:relative;
font-size:12px;
_height:18px;
}
#out, #out * {
padding:0;
margin:0;
}
#num {
height:16px;
line-h ......
ÒýÑÔ
ÒªÀí½â JavaScript£¬ÄãµÃÊ×ÏÈ·Å϶ÔÏóºÍÀàµÄ¸ÅÄ»Øµ½Êý¾ÝºÍ´úÂëµÄ±¾Ô¡£Ç°ÃæËµ¹ý£¬±à³ÌÊÀ½çÖ»ÓÐÊý¾ÝºÍ´úÂëÁ½ÖÖ»ù±¾ÔªËØ£¬¶øÕâÁ½ÖÖÔªËØÓÖÓÐמÀ²ø²»ÇåµÄ¹ØÏµ¡£JavaScript¾ÍÊǰÑÊý¾ÝºÍ´úÂë¶¼¼ò»¯µ½×îÔʼµÄ³Ì¶È¡£
»ù±¾ÀàÐÍ
Ò»¡¢¼òµ¥Êý¾ÝÀàÐÍ£ºundefined¡¢null¡¢boolean¡¢number¡¢string£¨×¢Ò⣺¶¼Ê ......
ÒýÑÔ
ÈκÎÒ»¸öº¯Êý¶¼¿ÉÒÔΪÆä¶¯Ì¬µØÌí¼Ó»òÈ¥³ýÊôÐÔ£¬ÕâЩÊôÐÔ¿ÉÒÔÊǼòµ¥ÀàÐÍ£¬¿ÉÒÔÊǶÔÏó£¬Ò²¿ÉÒÔÊÇÆäËûº¯Êý¡£Ò²¾ÍÊÇ˵£¬º¯Êý¾ßÓжÔÏóµÄÈ«²¿ÌØÕ÷£¬ÄãÍêÈ«¿ÉÒ԰Ѻ¯Êýµ±¶ÔÏóÀ´Óá£Æäʵ£¬º¯Êý¾ÍÊǶÔÏó£¬Ö»²»¹ý±ÈÒ»°ãµÄ¶ÔÏó¶àÁËÒ»¸öÀ¨ºÅ“()”²Ù×÷·û£¬Õâ¸ö²Ù×÷·ûÓÃÀ´Ö´Ðк¯ÊýµÄÂß¼¡£¼´£¬º¯Êý±¾Éí»¹¿ÉÒÔ±»µ÷ ......