Ïêϸ½â¶ÁJavaScriptµÄthis¹Ø¼ü×Ö
ÓÃÁ˺ܾÃJavaScript£¬¶Ô¡¾this¡¿µÄÈÏʶֻ¾ÖÏÞÓÚÒÔÍùµÄƾ¾Ñé¶øÒÑ£¬²»¹ý½ñÌì·¢ÏÖÁ˺ö«Î÷“http://www.quirksmode.org/js/associative.html”£¬ÏêϸÃèÊöÁËÈçºÎʹÓá¾this¡¿¹Ø¼ü×Ö£¬ÔÚÕâÀïÎҾͼò¶ÌµÄ˵һÏÂÖص㣬Èç¹ûÓÐÒÉÎÊ¿ÉÒÔÖ±½Ó²Î¿¼ÔÎÄ¡£
ÔÚѧϰ¹ýÓÐthisµÄ±à³ÌÓïÑÔÖУ¬thisÒ»°ã¶¼ÊÇÖ¸Ïòµ±Ç°ÊµÀý¶ÔÏóµÄ£¬¶ÔÓÚJavaScriptÀ´Ëµ£¬ÆäʵҲÊÇÕâÑù¡£µ«ÓÐʱºòÔÚʹÓá¾this¡¿Ê±£¬»á¸Ð¾õËüµÄÐÐΪºÜÆæ¹Ö£¬²»ÄÜÄÜ´ïµ½Ô¤ÆÚµÄЧ¹û£¬ÕâÍùÍùÊÇÒòΪûÓÐÕýÈ·µÄÁ˽⡾this¡¿±¾ÉíËùÖ¸ÏòµÄÕæÕýµÄʵÀý¶ÔÏóËùÒýÆðµÄ¡£
ÔÚJavaScriptÖУ¬¡¾this¡¿×ÜÊÇÖ¸ÏòÖ´Ðк¯ÊýµÄµ÷ÓÃÕߣ¬»òÕß¿ÉÒÔ˵ÊÇÖ¸ÏòÓµÓз½·¨µÄ¶ÔÏó¡£
function doSomething() {
this.style.color = '#cc0000';
}
Àý×ÓÖУ¬º¯Êý¡¾doSomething¡¿¶¨ÒåÔÚÒ³ÃæÖУ¬ËùÒÔËüÖ¸ÏòµÄ¾ÍÓ¦¸ÃÊǵ±Ç°Ò³Ã棬¼´È«¾Ö¶ÔÏó¡¾window¡¿¡£µ«ÊÇ£¬Èç¹ûÎÒÃÇÔÚÒ³ÃæÖÐij¸öÔªËصÄÊôÐÔÄÚ²¿Ê¹ÓÃÁË¡¾this¡¿£¬ÄÇô¡¾this¡¿Ö¸ÏòµÄÄÚÈݾÍÊÇÕâ¸öÔªËØ¡£ÈçÏÂÃæµÄÀý×Ó£¬¡¾this¡¿Ö¸µÄ¾ÍÊÇÔªËØ¡¾input¡¿¡£
<input type="button" value="Do not touch me!" onclick="alert(this.value);" />
ÔÙ¿´Ò»¸öÀඨÒåµÄÀý×Ó£º
function CSDN() {
this.url = "www.csdn.net";
this.author = "KNIGHTRCOM";
}
CSDN.prototype.output = function() {
alert(this.url + " - " + this.author);
}
new CSDN().output();
Ê×Ïȶ¨ÒåÒ»¸öÀࡾCSDN¡¿£¬²¢ÎªÕâ¸öÀàÌí¼ÓÒ»¸ö¡¾output¡¿·½·¨£¬output·½·¨ÄÚʹÓõġ¾this¡¿ËùÖ¸ÏòµÄÄÚÈÝ£¬¾ÍÊÇÀࡾCSDN¡¿µÄʵÀý¶ÔÏó¡¾new CSDN()¡¿¡£Ò²¾ÍÊÇ֮ǰ˵µÄ£¬¡¾this¡¿Ö¸ÏòÓµÓз½·¨¡¾output¡¿µÄʵÀý¶ÔÏó¡¾new CSDN()¡¿¡£
½ÓÏÂÀ´ÎÒÃÇÀ´Ñ§Ï°Ò»¸öÖØÒªµÄ¸ÅÄ¿½±´ÓëÒýÓá£
<mce:script type="text/javascript"><!--
element.onclick = doSomething;
// --></mce:script>
<element onclick="doSomething()">
ÎÒÃDZȽÏÒ»ÏÂÉÏÃæÁ½ÖÖÓ÷¨¡£µÚÒ»ÖÖÓ÷¨Êǽ«º¯Êý¡¾doSomething¡¿¿½±´µ½¡¾element¡¿µÄ¡¾onclick¡¿Ê¼þ¾ä±úÖУ¬ÕâÑù¡¾doSomething¡¿µÄÄÚÈݾͳÉΪԪËØ¡¾element¡¿µÄÒ»¸ö·½·¨£¬µ±¸Ã·½·¨±»Ö´ÐÐʱ£¬¡¾this¡¿ËùÖ¸ÏòµÄÄÚÈݼ´Îª·½·¨µÄÓµÓÐÕß¡¾element¡¿¡£µ«¶ÔÓÚµÚ¶þÖÖÓ÷¨£¨ÄÚÁª·½Ê½£©À´Ëµ£¬Êµ¼ÊÉÏÊÇÒ»ÖÖ±äÏàµÄµ÷Ó㬵±¡¾click¡¿Ê¼þ±»´¥·¢Ê±£¬¡¾doSomething¡¿È·Êµ»á±»µ÷Ó㬵«²¢·Ç×÷ΪԪËØ¡¾element¡¿µÄ·½·¨À´µ÷Óã¬ËùÒÔ¡¾this¡¿Ò²¾Í²»»áÖ¸Ïò¡¾element
Ïà¹ØÎĵµ£º
¢Ùfunction doDelete(){
var deleteArray = new Array();
var cnt = 0;
for (i = 0; i < document.forms[0].elements.length; i++ ) {
// ¥Á¥§¥Ã¥¯¥Ü¥Ã¥¯¥¹¤¬ON¤Î時¤Ï¤½¤Î値¤ò設¶¨¤¹¤ë¡£
......
var Sys = {};
var ua = navigator.userAgent.toLowerCase();
&nbs ......
תÔØ×Ô£ºhttp://www.zipeng.info/archives/ppk-on-js-events.html
½ñÌìÎÒ»á˵һЩ¹ØÓÚJavaScriptʼþµÄÊÂÇ飬ÎÒºÜÏ£Íû×Ô¼ºÄÜÆô·¢´ó¼ÒһЩʲô£¬²»¹ý´ó»ï¶¼ÊǸßÊÖ£¬²»¹ÜÔõô£¬ÎÒ»¹ÊÇҪ˵˵
JavaScriptʼþ¡£
´óÔ¼Ò»ÄêÇ°ÎÒ´òËã¶ÔJavaScriptµÄʼþ×öһЩÉîÈëµÄÑо¿£¬²¢ÇÒÎÒ×öÁËÒ»ÕżæÈÝÐÔµÄ±í£¬´ó¼Ò¿ÉÒÔͨ¹ýÏÂÃæÕâÀïÀ´
·ÃÎ ......
Ò»¸öͨÓõÄJavaScript·ÖÒ³
1.JavaScript´úÂë
Pagination=function(id)
{
var totalNum=0;
var maxNum=10;
var pageUrl="";
var breakpage = 5;
var currentposition = 0;
var breakspace = 2;
var maxspace = 4;
var currentpage=1;
var perpage=10;
var id =id;
this.initPage = function( ......