JavaScript prototype ÊôÐÔ
¶¨ÒåÓëÓ÷¨
The prototype property allows you to add properties and methods to an
object.
prototypeÊôÐÔÔÊÐíÄãÏòÒ»¸ö¶ÔÏóÌí¼ÓÊôÐԺͷ½·¨
Syntax
Óï·¨
object.prototype.name=value
Example 1
ʵÀý
In this example we will show how to use the prototype property to add a
property to an object:
ÔÚÏÂÃæµÄÀý×ÓÖУ¬ÎÒÃǽ«ÑÝʾÈçºÎÓÃprototypeÊôÐÔÀ´ÏòÒ»¸ö¶ÔÏóÔö¼ÓÒ»¸öÊôÐÔ£º
<script type="text/javascript">
function employee(name,jobtitle,born)
{
this.name=name
this.jobtitle=jobtitle
this.born=born
}
var fred=new employee("Fred Flintstone","Caveman",1970)
employee.prototype.salary=null
fred.salary=20000
document.write(fred.salary)
</script>
The output of the code above will be:
Êä³ö½á¹ûΪ£º
20000
Ïà¹ØÎĵµ£º
¶þʮһ¡¢ÉùÒô
1¡¢¿ÉÒÔ²¥·ÅÉùÒôµÄä¯ÀÀÆ÷£¨Audio-enabled Browsers£©
Q£ºÊ²Ã´¿ÉÒÔä¯ÀÀÆ÷¿ÉÒÔÖ´Ðв¥·ÅÉùÒôµÄ½Å±¾£¿
A£ºÈç¹ûÔÚÉùÒô²¥·ÅÃèÊöµÄ¼¼Êõ¿ÉÒÔÔÚMiscrosoft Internet Explorer 4.0¼°Æä¸üа汾Öй¤×÷£¬ÄÇôͬÑù¿ÉÒÔÔÚNetscape Navigator 3.0¼°Æä¸üа汾Öй¤×÷¡£ÒªÔÚInternet ExplorerÖв¥·ÅÉùÒô£¬ÔÚ4.0ÒÔ¼°ºóÀ´°æ±¾Ö ......
¶ÔÓÚJavaScriptµÄ Stack overflow at line ´íÎó×ܽá
¸Ã´íÎóÖ»ÔÚIEÖгöÏÖ£¬³öÏÖ¸ÃÌáʾµÄÔÒòÖ÷ÒªÓÐÁ½ÖÖ£º
1. Öض¨ÒåÁËϵͳµÄ´¥·¢Ê¼þÃû³Æ×÷Ϊ×Ô¶¨Ò庯ÊýÃûÈ磺 onclick / onsubmit ... ¶¼ÊÇϵͳ±£ÁôµÄʼþÃû³Æ£¬²»ÔÊÐí×÷ΪÖض¨Ò庯ÊýÃû³Æ¡£
2. ......
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>
Õâ¾ä ......
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>vForm±íµ¥ÑéÖ¤³Ì ......
//ºǫ́CSµ÷ÓÃǰ̨JS·½·¨
ClientScript.RegisterStartupScript(this.GetType(), "onclick", "<script>CheckInput()</script>");
//УÑéÊäÈë¿òÊÇ·ñΪ¿Õ£¬Ð£ÑéÊÇ·ñÊÇÊý×Ö
<script type="text/javascript" language="javascript">
function CheckInput ......