Javascript¼Ì³Ð»úÖÆ£¨call¡¢apply¡¢prototype£©
JavascriptµÄ¼Ì³Ð¿ÉÒÔͨ¹ýcall¡¢apply¡¢prototypeʵÏÖ¡£
1¡¢call£ºÔÚ×ÓÀàÖУ¬Óø¸Àà.call£¨this£¬arg0£¬arg1...£©¿ÉÒԼ̳и¸Àà¡£×¢ÒâcallµÄλÖ㬾¡Á¿ÔÚ×ÓÀàµÄµÚÒ»ÐУ¨js°´Ë³ÐòÖ´ÐУ¬·ÅÔÚºóÃæ¿ÉÄܶÔ×ÓÀàµÄÆäËûÊôÐÔ¡¢·½·¨ÓÐÓ°Ïì¡£±ÈÈç×ÓÀàºÍ¸¸ÀàÓÐÏàͬÃû×ֵķ½·¨£¬ºóÃæµÄ¸²¸ÇÇ°ÃæµÄ£©¡£
<html>
<head>
<title>call\apply\prototype test</title>
</head>
<script type="text/javascript">
//personÀà
function person(name, age) {
this.name = name;
this.age = age;
this.say = function() {
document.write("I am a person");
}
this.display = function() {
document.write(this.name + "-" + this.age);
}
}
//studentÀ࣬¼Ì³Ð×Ôperson
function student(name, age, no) {
person.call(this, name, age);//personÖеÄthisµÈÓÚ²ÎÊýÖеÄthis£¬¼´studentÖеÄnameºÍage
this.no = no;
this.display = function() {//¸²¸ÇÁ˸¸ÀàµÄ·½·¨
document.write(this.name + "-" + this.age + "-" + this.no);
}
}
//´´½¨personÀà
var p = new person("captain", 21);
p.display();//captain-21
p.say();//I am a person
//´´½¨studentÀà
var s = new student("captain", 21, "06281097")
s.display();//captain-21-06281097
s.say();//I am a person ¼Ì³ÐÁ˸¸ÀàµÄ·½·¨
<script>
<body>
</body>
</html>
2¡¢apply£ºÔÚ×ÓÀàÖУ¬Óø¸Àà.apply£¨this£¬args£©¿ÉÒԼ̳и¸ÀࣨargsΪ²ÎÊýÊý×飩¡£
<html>
<head>
<title>call\apply\prototype test</title>
</head>
<script type="text/javascript">
//personÀà
function person(name, age) {
this.name = name;
this.age = age;
this.say = function() {
document.write("I am a person");
}
this.display = function() {
document.write(this.name + "-" + this.age);
}
}
//studentÀ࣬¼Ì³Ð×Ôperson
function student(name, age, no) {
person.apply(this, new Array(name, age));//Óëcall²»Í¬µÄÊÇ£¬apply´«µÝµÄÊÇÊý×é
this.no = no;
this.display = function() {//¸²¸ÇÁ˸¸ÀàµÄ·½·¨
document.write(this.name + "-" + this.age + "-" + this.no);
}
}
//´´½¨pe
Ïà¹ØÎĵµ£º
<script language=JAVAscript>
var s="b";
var strCode
for(var i=0;i<s.length;i++)
{
strCode=s.charCodeAt(i);
if((strCode>65248)||(strCode==12288))
{
alert("ÓÐÈ«½Ç");
break;
}
}
</script>
°ë½Ç×Ö·ûÓÉÒ»¸ö×Ö½Ú±£´æ£¬È«½Ç×Ö·ûÓÃÁ½¸ö×Ö½Ú±£´æ
ËùÒÔÂëÖµµÄ¾ø¶ÔֵСÓÚ256µÄ¾ÍÊǰë½Ç£¬· ......
Ç°Ì¨Ò³ÃæÎª ×ÓÒ³ÃæÎªÒ»¸ö°´Å¥£º
<form id="form1" runat="server">
<div>
<asp:Button runat="server" ID="Bt_Add" Text="Ìí¼Ó" Width="80px" Height="20px" OnClick="Bt_Add_Click" />
</div>
  ......
½ñÌìÒªÏò´ó¼ÒÍÆ¼ö9¿îºÜ°ôµÄ¿ÉÔÚÍøÒ³ÖлæÖÆÍ¼±íµÄJavaScript½Å±¾£¬ÕâЩÓÐȤµÄJS½Å±¾¿ÉÒÔ°ïÖúÄã¿ìËÙ·½±ãµÄ»æÖÆÍ¼±í£¨Ïß¡¢Ãæ¡¢±ý¡¢Ìõ…£©£¬ÆäÖаüÀ¨jQuery¡¢MooTools¡¢PrototypeºÍһЩÆäËüµÄJavaScript¿ò¼Ü¡£
Äú»¹¿ÉÒԲο¼ÒÔÏÂJavaScript/CSSÏà¹Ø½Ì³Ì¼°×ÊÔ´:
¡¶¾«Ñ¡30¸öÓÅÐãµÄCSS¼¼Ê ......
1:js ×Ö·û´®³¤¶ÈÏÞÖÆ¡¢ÅжÏ×Ö·û³¤¶È¡¢jsÏÞÖÆÊäÈë¡¢ÏÞÖÆ²»ÄÜÊäÈë¡¢textarea ³¤¶ÈÏÞÖÆ
2.:jsÅжϺº×Ö¡¢ÅжÏÊÇ·ñºº×Ö ¡¢Ö»ÄÜÊäÈ뺺×Ö
3:jsÅжÏÊÇ·ñÊäÈëÓ¢ÎÄ¡¢Ö»ÄÜÊäÈëÓ¢ÎÄ
4:jsÖ»ÄÜÊäÈëÊý×Ö,ÅжÏÊý×Ö¡¢ÑéÖ¤Êý×Ö¡¢¼ì²âÊý×Ö¡¢ÅжÏÊÇ·ñΪÊý×Ö¡¢Ö»ÄÜÊäÈëÊý×Ö
5:Ö»ÄÜÊäÈëÓ¢ÎÄ×Ö·ûºÍÊý×Ö
6: js emailÑéÖ¤ ¡¢js ÅжÏemail ¡¢ÐÅÏä ......
1. oncontextmenu="window.event.returnValue=false" ½«³¹µ×ÆÁ±ÎÊó±êÓÒ¼ü
<table border oncontextmenu=return(false)><td>no</table> ¿ÉÓÃÓÚTable
2. <body onselectstart="return false"> È¡Ïûѡȡ¡¢·ÀÖ¹¸´ÖÆ
3. onpaste="return false" ²»×¼Õ³Ìù
4. oncopy="return false;" oncut="return f ......