日期:2014-05-16  浏览次数:20400 次

javascript問題
1.There   is   another   concept   related   to   using   return   false   in   an   event   handler.   If   you   fully   handle   a   given
event   in   a   contained   control,   you   may   not   want   that   same   event   to   “bubble   up”   to   any   parent   controls   it
is   within.   For   instance   in   the   previous   example,   you   may   not   want   the   onclick   event   on   the   <a>   to   be
seen   by   an   onclick   handler   for   the   <body>   element.   But   by   virtue   of   <a>   being   a   child   element   under
<body> ,   normally   this   onclick   would   bubble   up.   If   you   use   only   return   false,   then   it   will   defer
what   would   happen   on   the   <a>   but   not   what   would   happen   in   an   onclick   on   the   <body> .   To   keep   this
from   happening,   use   this   statement:

event.cancelBubble=true;

You   must   use   this   statement   before   any   return   because   executing   return   indicates   that   you’re   done
with   the   event   handler   code   and   want   to   return   control   to   the   browser.
如果我有100個button需要寫alert( "* ");
event.cancelBubble=true;是沈麼意思,可以實現嗎?
2.
You   don’t   always   want   script   to   be   executed   as   the   page   is   loaded.   Quite   often   you   want   script   executed   in
response   to   events   such   as   a   user   clicking   a   particular   screen   element   or   a   mouse   movement.   (For   example,
you   may   recall   that   in   Chapter   2,   you   used   the   onload   event   to   insert   custom   text   into   the   status
area   of   a   browser   window   once   a   page   had   fully   rendered.)   This   activity   is   usually   done   by   referencing
either   inline   JavaScript   or   a   function   using   an   XHTML   attribute.   In   the   following   examples,   you   are   handling
the   onclick   event   of   a   button   first   using   inline   script:
<input   type=”button”   value=”Click   Me   (inline)”   onclick=”alert(‘I   was   clicked   -
inline   script’);”   />
and   then   using   a   HandleClick()   function:
<input   type=”button”   value=”Click   Me   (function)”   onclick=”HandleClick();”   />
The   onclick   event   is   probably   one   of   the   most   familiar   events   to   web   developers   and   doesn’t   have   to   be
a