javascript thisÏê½â£¨×ª£©
ÔÚÃæÏò¶ÔÏó±à³ÌÓïÑÔÖУ¬¶ÔÓÚthis¹Ø¼ü×ÖÎÒÃÇÊǷdz£ÊìϤµÄ¡£±ÈÈçC++¡¢C#ºÍJavaµÈ¶¼ÌṩÁËÕâ¸ö¹Ø ¼ü×Ö£¬ËäÈ»ÔÚ¿ªÊ¼Ñ§Ï°µÄʱºò¾õµÃ±È½ÏÄÑ£¬µ«Ö»ÒªÀí½âÁË£¬ÓÃÆðÀ´ÊǷdz£·½±ãºÍÒâÒåÈ·¶¨µÄ¡£JavaScriptÒ²ÌṩÁËÕâ¸öthis¹Ø¼ü×Ö£¬²»¹ýÓÃÆðÀ´¾Í±È ¾µäOOÓïÑÔÖÐÒª"»ìÂÒ"µÄ¶àÁË¡£
ÏÂÃæ¾ÍÀ´¿´¿´£¬ÔÚJavaScriptÖи÷ÖÖthisµÄʹÓ÷½·¨ÓÐʲô»ìÂÒÖ®´¦£¿
1¡¢ÔÚHTMLÔªËØʼþÊôÐÔÖÐinline·½Ê½Ê¹ÓÃthis¹Ø¼ü×Ö£º
<div onclick="
// ¿ÉÒÔÔÚÀïÃæʹÓÃthis
">division element</div>
ÎÒÃÇÒ»°ã±È½Ï³£Óõķ½·¨ÊÇÔÚ´ËʹÓãºjavascirpt: EventHandler(this)£¬ÕâÑùµÄÐÎʽ¡£²»¹ýÕâÀïÆäʵ¿ÉÒÔдÈκκϷ¨µÄJavaScriptÓï¾ä£¬ÒªÊǸßÐËÔڴ˶¨Òå¸öÀàÒ²¿ÉÒÔ(²»¹ý½«»áÊǸö ÄÚ²¿Àà)¡£ÕâÀïµÄÔÀíÊǽű¾ÒýÇæÉú³ÉÁËÒ»¸ödivʵÀý¶ÔÏóµÄÄäÃû³ÉÔ±·½·¨£¬¶øonclickÖ¸ÏòÕâ¸ö·½·¨¡£
2¡¢ÓÃDOM·½Ê½ÔÚʼþ´¦Àíº¯ÊýÖÐʹÓÃthis¹Ø¼ü×Ö£º
<div id="elmtDiv">division element</div>
<script language="javascript">
var div = document.getElementById('elmtDiv');
div.attachEvent('onclick', EventHandler);
function EventHandler()
{
// ÔÚ´ËʹÓÃthis
}
</script>
ÕâʱµÄEventHandler()·½·¨ÖеÄthis¹Ø¼ü×Ö£¬Ö¸Ê¾µÄ¶ÔÏóÊÇIEµÄwindow¶ÔÏó¡£ÕâÊÇÒòΪ EventHandlerÖ»ÊÇÒ»¸öÆÕͨµÄº¯Êý£¬¶ÔÓÚattachEventºó£¬½Å±¾ÒýÇæ¶ÔËüµÄµ÷ÓúÍdiv¶ÔÏó±¾ÉíûÓÐÈκεĹØϵ¡£Í¬Ê±Äã¿ÉÒÔÔÙ¿´¿´ EventHandlerµÄcallerÊôÐÔ£¬ËüÊǵÈÓÚnullµÄ¡£Èç¹ûÎÒÃÇÒªÔÚÕâ¸ö·½·¨ÖлñµÃ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ÔªËضÔÏóʵÀý£¬Ôڽű
Ïà¹ØÎĵµ£º
ÔÚ×Ô¼ºµÄÍøÕ¾ÉϸüÐÂÎÄÕÂʱһ¸ö±È½Ï³£¼ûµÄÎÊÌâÊÇ£ºÎÄÕ²åͼ̫¿í£¬Ê¹Õû¸öÍøÒ³¶¼±äÐÎÁË¡£Èç¹û¶Ôÿ¸ö²åͼ¶¼ÏȽøÐÐËõ·ÅÔÙ²åÈëµÄ»°£¬Ì«Âé·³ÁË¡£
ÎÒÇ°¶Îʱ¼äдµÄһƪÎÄÕ¾ÍÓöµ½¹ýÕâÖÖÊÂÇ飬ºóÀ´ÓÃCSSµÄoverflowºÍmax-widthÊôÐÔÔÝʱ½â¾öÁËÒ³Ãæ±äÐεÄÎÊÌâ¡£ÕâÖÖ·½·¨ºÃ´¦ÊǼòµ¥£¬µ«»µ´¦ÊÇ»áÆÆ»µÄ³Ð©Ï¸½ÚµÄЧ¹û¡£
Èçoverflow£ºhidden ......
½ñÌìÔÚ×öÒ»¸öѧÉúÐÅÏ¢ÐÞ¸ÄÒ³ÃæµÄʱºòÓöµ½ÁËÒ»µãСÎÊÌ⣬ÒòÐèÇóÖ¸³öѧÉúÔڲ鿴¸öÈËÐÅϢʱ¿ÉÒÔÉê¸æÆäÖеĴíÎóÐÅÏ¢£¬²¢Ìá½»ÕýÈ·ÐÅÏ¢£¬ËùÒÔÎÒÔÚÏÔʾ»ù±¾ÐÅÏ¢µÄʱºò¶ÔÓÚѧԺ¡¢×¨ÒµºÍ°à¼¶µÈ¾Í²ÉÓÃÁËÏÂÀ²Ëµ¥£¬ÎªÁËʹÏÂÀ²Ëµ¥ÏÔʾѧÉúµ±Ç°µÄÐÅÏ¢£¬ÇÒ¾ßÓÐÁª¶¯Ð§¹ûÐèÔÚjsÖлñÈ¡sessionÖд«¹ýÀ´µÄÏà ......
ÒÔÏÂÈ«ÊǸöÈËÀí½âÒÔ¼°ÍøÉϲéÕÒ¶øÀ´,ÈçÓ⻶ÔÇëÖ¸Õý...
¼ÙÈçÓÐn¶Îjs´úÂë ÓÃ<script>±êÇ©¸ô¿ªµÄ.
ÔËÐÐ˳ÐòÊÇ
step1. ¶ÁÈëµÚÒ»¸ö´úÂë¶Î
step2. ×öÓï·¨·ÖÎö£¬ÓдíÔò±¨Óï·¨´íÎ󣨱ÈÈçÀ¨ºÅ²»Æ¥ÅäµÈ£©£¬²¢Ìøתµ½step5
step3. ¶Ôvar±äÁ¿ºÍfunction¶¨Òå×ö“Ô¤½âÎö”£¨ÓÀÔ¶²»»á±¨´íµÄ£¬ÒòΪֻ½âÎöÕýÈ·µÄÉùÃ÷£©
......
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<title>¹ö¶¯ÐÂÎÅÀà</title>
<style type="text/css">
body {
  ......
<html>
<body>
<SCRIPT type="text/javascript">
<!--
var target=[]
var time_id=[]
function ShowDateTime(){
setTimeout("ShowDateTime()", 1000);
for (var i=0,j=target.length;i<j;i++)
{
var today=new Date();
timeo ......