javascriptдÀ෽ʽ֮Áù
ÕâÆª¿ªÊ¼»á·ÖÎöÁ÷ÐеÄjs¿â֮дÀ෽ʽ¡£¸÷ÖÖ¿âµÄдÀ෽ʽËäÈ»Ç§Ææ°Ù¹Ö£¬µ«ÈÔÈ»ÌÓÀë²»Á˱¾ÖÊ---Óù¹Ô캯ÊýºÍÔÐÍ
À´×é×°Àà¡£
6¡¢Prototype.jsµÄдÀ෽ʽ
//prototype.jsÖеĴúÂë
var Class = {
create: function() {
return function() {
this.initialize.apply(this, arguments);
}
}
}
//¼ò»¯ºóµÄ
function Clazz() {
return function(){
this.initialize.apply(this,arguments);
}
}
Èçϲ½Öèдһ¸öÀ࣬
//ˈ̞Person
var Person = Class.create();
//ͨ¹ýÔÐÍÖØÐ´À´¶¨ÒåPerson
Person.prototype = {
initialize : function(name) {
this.name = name;
},
getName : function() {
return this.name;
},
setName : function(name) {
this.name = name;
}
}
//´´½¨¶ÔÏó
var p = new Person("jack");
console.log(p.constructor == Person);//false
initializeÍê³É¶ÔÏóµÄ³õʼ»¯£¨Ï൱ÓÚ¹¹Ô캯Êý£©£¬·½·¨ÒÀ´ÎÍùÏÂд¼´¿É¡£
ÓиöÎÊÌ⣬ͨ¹ýÕâ¾äp.constructor ==
PersonΪfalse¿ÉÒÔ¿´µ½£¬ÕâÕýÊÇPrototype.jsÒ»¸öССµÄȱÏÝ¡£ÔÒòÊÇÖØÐ´ÁËPersonµÄÔÐÍ¡£ÎªÁËʹconstructorÄÜÖ¸
ÏòÕýÈ·µÄ¹¹ÔìÆ÷£¬Ö»ÐèÔÚÔÐÍÖØÐ´Ê±Î¬»¤ºÃconstructorÊôÐÔ¼´¿É¡£
Person.prototype = {
constructor : Person,//×¢ÒâÕâÀï
initialize : function(name) {
this.name = name;
},
getName : function() {
return this.name;
},
setName : function(name) {
this.name = name;
}
}
ºÃÁË£¬Õâʱºòp.constructor == Person¾ÍÊÇtrueÁË¡£
Ïà¹ØÎĵµ£º
±¾ÎÄÁоÙÁ˸÷ÖÖJavaScript¶ÔÏóÓëÊý×é,ͬʱ°üÀ¨¶ÔÉÏÊöÿһ¶ÔÏó»òÊý×éËùÍê³É¹¤×÷µÄ¼ò¶ÌÃèÊö,ÒÔ¼°ÓëÆäÏà¹ØµÄÊôÐÔ·½·¨,ÒÔ¼°Ê¼þ´¦Àí³ÌÐò¡£
¡¡¡¡B.1 anchor¶ÔÏó
¡¡¡¡Ê¹ÓÃ<A NAME=>±ê¼Ç´´½¨µÄHTMLÃèµãÄܱ»Ò»¸öÁ´½Ó×÷ΪĿ±êÈç¹ûêµã°üÀ¨HREF=ÌØÐÔ,ÔòËüÒ²ÊÇÒ»¸öÁ´½Ó¶ÔÏó¡£
¡¡¡¡anchor¶ÔÏóÊÇdocument¶ÔÏóµÄÒ»¸öÊôÐÔ,Ëü±¾Éíà ......
1¡¡¾Ö²¿´òÓ¡·½·¨£º
×÷Ó㺽«idΪdayinµÄÄÚÈÝ£¬Ð½¨Ò³Ãæ²¢´òÓ¡£¬¿É½â¾ö´òÓ¡Ä³Ò³ÃæÖеIJ¿·ÖÄÚÈݵÄÎÊÌâ¡£
ʹÓ÷½·¨£º½«Òª´òÓ¡µÄÄÚÈÝͨ¹ý <span id="dayin"></span>°üº¬ÆðÀ´£¬È»ºóÔÚij¸ö°´Å¤Öж¨Òå
ʼþ
<input type="button" onclick="dayin()" value="´òÓ¡">
function dayin()
{
......
Build your web applications quickly and easily using the industry leading web application IDE -- Aptana Studio.
Introduction:
Aptana Studio is a complete web development environment that combines powerful authoring tools for HTML, CSS, and JavaScript, along with thousands of additional plugins ......
//the common event,If your brower is firefox,you should use this function instead of "window.event"
function getEvent() {
if(document.all)
return window.event; //get ie event
func=getEvent.caller;
while(func!=null) {
......
function $id(s) {
return document.getElementById(s);
}
//ÅжÏСÊý
function IsFloat(s) {
if (!/^[+\-]?\d+(.\d+)?$/.test(s))
return false;
else
return ......