JavaScript ¼Ì³Ð
myhere
// ѧϰҪÏ뿽±´ÄÇô¿ì¾ÍºÃÁË
//
// JavaScript µÄ¼Ì³ÐÊÇ»ùÓÚ prototype µÄ£¬Ã¿¸ö¶ÔÏóµÄ prototype ÊDZ£´æÔÚ¶ÔÏóµÄ __proto__ ÊôÐÔÖеģ¬Õâ¸öÊôÐÔÊÇÄÚ²¿(internal)µÄÊôÐÔ( ¹ßÀýÊÇÄÚ²¿µÄ»òÕßÒþ²ØµÄÊôÐÔÒÔ _ ¿ªÍ·)
// A prototype-based language has the notion of a prototypical object, an object used as a template from which to get the initial properties for a new object.
//
/**
* Property lookup in Javascript looks within an object's own properties and,
* if the property name is not found, it looks within the special object property __proto__.
* This continues recursively; the process is called "lookup in the prototype chain".
* The special property __proto__ is set when an object is constructed;
* it is set to the value of the constructor's prototype property.
* So the expression new Foo() creates an object with __proto__ == Foo.prototype.
* Consequently, changes to the properties of Foo.prototype alters the property lookup for all objects that were created by new Foo().
*/
// ¸ø¶ÔÏóµÄÔÐÍÔö¼Ó³ÉÔ±»áÁ¢¼´ÔڸöÔÏóÖпɼû
function Base(){
this.name = 'myhere';
}
function Sub(){
this.age = 23;
}
Sub.prototype = new Base(); // ¸øÔÐ͸³ÖµÎªÒ»¸ö==¶ÔÏó==¡£
var me = new Sub();
// ´´½¨¶ÔÏóºó¸øÔÐÍÔö¼Ó sex ÊôÐÔ£¬¸ÃÊôÐÔÁ¢¼´ÔÚ¶ÔÏóÖпɼû
Base.prototype.sex = 'male';
var str = '';
str += me.name + me.age + me.sex;
document.write( str); // myhere23male
/**
* ˵Ã÷£º
* ¶ÔÓÚÕâÖּ̳У¬ÔÚÆµ·±ÐÞ¸ÄÔÐ͵ÄÇé¿öϾͱäµÃ»ìÂÒÁË
*/
//
/**
* ÁíÒ»Öּ̳з½·¨
*/
function Base(){
this.name = 'myhere';
}
// ²¢Ã»Óн« Sub µÄÔÐ͸³ÖµÎª Base£¬Ö»ÊÇÔÚ Sub Öе÷Óà Base º¯Êý
function Sub(){
this.age = 23;
Base.call( this); // Ö»Êǽ«Ò»²¿·Ö³õʼ»¯½»¸ø Base º¯Êý£¬²¢Ã»ÓвÙ×÷ prototype
}
var me = new Sub();
Base.prototype.sex = 'male'; // ÐÞ¸Ä Base ²»»áÓ°Ïì Sub µÄ¶ÔÏó£¬ÒòΪ Base ²¢²»ÊÇ Sub µÄÔÐÍ
// Èç¹û½«Õâ¸öÔö¼Ó sex µÄÓï¾ä·Åµ½ Sub ¶¨Òåǰ£¬ÔÚ me ÖÐÒ²µÃ²»µ½ sex ÊôÐÔ£¬
// ÒòΪ Base.call() Ö»Êǵ÷Óà Base º¯Êý¶øÒÑ
var str = '';
str += me.name + m
Ïà¹ØÎĵµ£º
ת×Ô£º
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>ͼƬÅÜÂíµÆ</title>
</head>
<body>
<div style="overflow:hidden; width:350px" id='div'>
<!-- ÕâÀïÊǵÚÒ»¸ö¹Ø¼üµã£¬o ......
µÚÈýÕÂ ¶ÔÏó»ù´¡
ÔÚjavaScriptÖУ¬¶ÔÏóÊÇÎÞÌØ¶¨Ë³ÐòµÄÖµµÄÊý×é¡£
Ò»¡¢¶ÔÏóµÄÀàÐÍ
·ÖΪ±¾µØ¶ÔÏó¡¢ÄÚÖöÔÏóºÍËÞÖ÷¶ÔÏóÈýÖÖ£¬ÆäÖÐÄÚÖöÔÏóÒ²ÊôÓÚ±¾µØ¶ÔÏó¡£
¶þ¡¢±¾µØ¶ÔÏó£º
1¡¢ArrayÀ࣬Êý×éÀà¡£
  ......
<div id="imgbox" style="height:110px;width:600px;overflow:hidden;">
<div id="imgbox1" style="float:left;width:1000%">
<img src="http://www.google.com.hk/intl/zh-CN/images/logo_cn.gif" mce_src="http://www.google.com.hk/intl/zh-CN/images/logo_cn.gif">
<img src="http://www ......
1. BooleanÖµ¡¢Êý×Ö¡¢×Ö·û´®µÄÔʼֵÊÇα¶ÔÏó£¬ÕâÒâζ×ÅËûÃǾßÓÐÊôÐԺͷ½·¨¡£
var test = "hello";
alert(test.length); //outputs "5"
2. javascript Ëù¶¨ÒåµÄËùÓжÔÏó¶¼ÓÐ toString() ·½·¨£¬²»¹ÜÊÇα¶ÔÏó»¹ÊÇÕæµÄ¶ÔÏó£¬Boolean µÄ toString() ·½·¨Ö»·µ»Ø “true” »òÕß“false”¡£
var t ......
²»Óò»ÖªµÀ,Ò»ÓòÅÖªµÀÕâÁ½ÕßÊDz»´óÒ»ÑùµÄ,ÏñÔÚjavaÖÐ,ÊÇÖ±½ÓʹÓà ,Èç str1.replace("$","*") °Ñ$ºÅ±ä³É*ºÅ
µ«ÔÚjavascript¾Í²»Ò»Ñù,ҪʵÏÖÉÏÃæµÄ¹¦ÄÜÊÇÕâÑùд: str.replace(/&/g,"*") ÆäÖеÄgÊDzÎÊý,˵Ã÷Òª½«È«²¿µÄ$¶¼±ä³É*
ÏÂÃæ°ÑjavascriptµÄÕ³ÌùÔÚÏÂÃæ:
¶¨ÒåºÍÓ÷¨
replace() ·½·¨ÓÃÓÚÔÚ×Ö·û´®ÖÐÓÃһЩ×Ö·ûÌ ......