I recently encountered a related bug when I called netsurf: alert () was called twice. Html code:
Copy codeThe Code is as follows:
<Html>
<Head>
<Title> alert onclick example </title>
<Script type = "text/javascript">
Function causealert ()
{
Var txt = document. getElementById ("p1"). textContent;
Alert (txt );
}
</Script>
</Head>
<Body>
<Div style = "border: 1px solid red">
<P id = "p1"> First line of paragraph. <br/> </p>
</Div> <br/>
<Button id = "button1"> add another textNode. </button>
<Script>
Var Button1 = document. getElementById ("button1 ");
/* Var Button1Click = function () {alert (1 );};
Button1.addEventListener ("click", Button1Click, false );*/
Button1.onclick = causealert;
</Script>
</Body>
</Html>
Through gdb, locate the problem in _ dom_node_dispatch_event:
Copy codeThe Code is as follows:
/* The capture phase */for (targetnr = ntargets; targetnr> 0; -- targetnr )...
/* Bubbling phase */
Evt-> phase = DOM_BUBBLING_PHASE;
For (targetnr = 0; targetnr <ntargets; ++ targetnr)
The event stream is like this: p1 (root) --> p2 -->... --> pm --> T (capturing phase), T (target phase), T --> pm -->... --> p1 (bubbling phase ).
The specification specifies that capturing and bubbling can only be selected. In the code, the js_dom_event_add_listener () option is capturing. This explains why alert was executed twice.
Modify: Change the preceding 0 to 1 according to the DOM 3 specification.