javascript ÖÐthis µÄÓ÷¨:
javascript ÖÐthis µÄÓ÷¨:
1.<div onclick="// ¿ÉÒÔÔÚÀïÃæʹÓÃthis">division element</div> this Ö¸Ïòdiv
2. <div id="elmtDiv">division element</div>
<script language="javascript">
var div = document.getElementById('elmtDiv');
div.attachEvent('onclick', EventHandler); //attachEvent°ÑdivµÄonclickʼþºÍÒ»¸ö·½·¨°ó¶¨
function EventHandler()
{
// ÔÚ´ËʹÓÃthis
}
</script>ÔÚ´Ëthis Ö¸Ïòwindow¶ÔÏó,ÈôÒªÒýÓÃdiv¶ÔÏóthis.event.srcElement;
3¡¢ÓÃDHTML·½Ê½ÔÚʼþ´¦Àíº¯ÊýÖÐʹÓÃthis¹Ø¼ü×Ö£º
<div id="elmtDiv">division element</div>
<script language="javascript">
var div = document.getElementById('elmtDiv');
div.onclick = function()
{
// ÔÚ´ËʹÓÃthis
};
</script>²úÉúµÄ·½·¨Í¬ÉÏ,µ«´Ë´¦µÄthis Ö¸Ïòdiv
4¡¢ÀඨÒåÖÐʹÓÃthis¹Ø¼ü×Ö£º
function JSClass()
{
var myName = 'jsclass';
this.m_Name = 'JSClass';
}
JSClass.prototype.ToString = function()
{
alert(myName + ', ' + this.m_Name);
};
var jc = new JSClass();
jc.ToString();//ÕâÊÇJavaScriptÄ£ÄâÀඨÒåÖжÔthisµÄʹÓã¬Õâ¸öºÍÆäËüµÄOOÓïÑÔÖеÄÇé¿ö·Ç³£µÄÏàʶ¡£µ«ÊÇÕâÀïÒªÇó³ÉÔ±ÊôÐԺͷ½·¨±ØÐëʹÓÃthis¹Ø¼ü×ÖÀ´ÒýÓã¬ÔËÐÐÉÏÃæµÄ³ÌÐò»á±»¸æÖªmyName䶨Òå¡£
5¡¢Îª½Å±¾ÒýÇæÄÚ²¿¶ÔÏóÌí¼ÓÔÐη½·¨ÖеÄthis¹Ø¼ü×Ö£º
Function.prototype.GetName = function()
{
var fnName = this.toString();
fnName = fnName.substr(0, fnName.indexOf('('
Ïà¹ØÎĵµ£º
±Õ°ü£º
ECMAScriptÖ§³Ö±Õ°ü¡£Ëùν±Õ°ü£¬¾ÍÊǺ¯ÊýÄÜʹÓú¯ÊýÍⶨÒåµÄ±äÁ¿¡£
var iBaseNum = 10;
function addNumbers(iNum1, iNum2)
{
function doAddition()
......
ÕýÔÚ¿´¡¡javascript¸ß¼¶³ÌÐòÉè¼Æ¡¡,ÆäÖйØÓÚ·Ö×éÀïÃæµÄÒ»¾ä´úÂë²»ÊÇÌ«Àí½â:
ͨ¹ýÅäºÏʹÓÃString¶ÔÏóµÄreplace()·½·¨¼°·´ÏòÒýÓ㬾ͿÉÒÔ¶¨Òå×Ô¼ºµÄtrim()·½·¨:
String.prototype.trim = function() {
var reExtraSpace = /^\s+(.*?)\s+$/;
return this.replace(reExtraSpace,"$1");
}
Ò»¿ªÊ¼ÔõôҲ²» ......
Arguments
¸Ã¶ÔÏó´ú±íÕýÔÚÖ´Ðеĺ¯ÊýºÍµ÷ÓÃËüµÄº¯ÊýµÄ²ÎÊý¡£
[function.]arguments[n]
²ÎÊý
function £ºÑ¡Ïî¡£µ±Ç°ÕýÔÚÖ´ÐÐµÄ Function ¶ÔÏóµÄÃû×Ö¡£
n £ºÑ¡Ïî¡£Òª´«µÝ¸ø Function ¶ÔÏóµÄ´Ó0¿ªÊ¼µÄ²ÎÊýÖµË÷Òý¡£
˵Ã÷
ArgumentsÊǽøÐк¯Êýµ÷ÓÃʱ£¬³ýÁËÖ¸¶¨µÄ²ÎÊýÍ⣬»¹ÁíÍâ´´½¨µÄÒ»¸öÒþ²Ø¶ÔÏó¡£ArgumentsÊÇÒ»¸öÀàËÆ ......
jQuery, MooTools, Prototype µÈÓÅÐãµÄ
JavaScript ¿ò¼ÜÓµÓи÷ÖÖÇ¿´óµÄ¹¦ÄÜ£¬°üÀ¨»æÖÆ Web ͼ±í£¬Ê¹ÓÃÕâЩ¿ò¼ÜÒÔ¼°ÏàÓ¦²å¼þ£¬ÎÒÃÇ¿ÉÒԷdz£ÇáËɵØʵÏÖÇúÏßͼ£¬Ô²±ýͼ£¬Öù״ͼµÈ
Web ͼ±íµÄ»æÖÆ£¬¶ø²»±ØÏóÒÔÍùÄÇÑùͨ¹ý¸´Ô Flash ¼¼ÊõʵÏÖ¡£±¾ÎĽéÉÜÁË9¸öÓÅÐãµÄ»ùÓÚ JavaScript Óë CSS& ......
1.Date
ÊôÐÔ(1):
constructor Ëù½¨Á¢¶ÔÏóµÄº¯Êý²Î¿¼
prototype Äܹ»Îª¶ÔÏó¼ÓÈëµÄÊôÐԺͷ½·¨
·½·¨(43):
getDay() ·µ»ØÒ»ÖÜÖеĵڼ¸Ìì(0-6)
getYear() ·µ»ØÄ ......