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.
如果我有100button需要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
applied only to obvious items such as buttons. It can be applied to other items such as paragraph tags,
<p> , and most other items as well.
<p onclick=”HandleParaTagClick();”> This is some paragraph text </p>
inline HandleParaTagClick()都是甚?
甚教科里,有定的函呀!
[解决办法]
event.cancelBubble=true; 这是IE实现的事件机制, 防止事件向上传播.
比如你在td中点击了一下,那么正常情况下,事件会向上传播,tr会得到onclick事件,table也会,body会,最后,document也会得到. 设置event.cancelBubble=true;后, 事件不向上传播了
HandleParaTagClick()是自定义的函数,看不到不代表没有