Home  >  Article  >  Web Front-end  >  3 puzzles about DOM elements and events_DOM

3 puzzles about DOM elements and events_DOM

WBOY
WBOYOriginal
2016-05-16 18:16:371033browse
1. Introduction to background knowledge
Usually there are the following ways to add events to DOM elements:
1. Hard-coded form
2. Event monitoring
3. Provided by JS framework Event binding
1, hard-coded form, adopts the form of original event (Original Event).
The code is similar to the following:
Copy the code The code is as follows:


document.getElementById('element_id').eventName = func();

2, event listening mechanism, the approach adopted in this form is based on DOM event mechanism is divided into DOM standard event model addEventListener and IE event model attchEvent.
The code is similar to the following:
Copy the code The code is as follows:

var addEventHandler = function( ele, evt, fn){
if (ele.addEventListener) {
ele.addEventListener(evt, fn, false);
}
else
if (ele.attachEvent) {
ele.attachEvent('on' evt, fn);
}
else {
ele['on' evt] = fn;
}
};
var ele = document.getElementById('element_id');
addEventHandler(ele, 'eventName', function(){ code... });

3, event binding provided by JS framework Mechanism, here it is assumed that the jQuery framework is used.
The code is similar to the following:
Copy the code The code is as follows:

$('element_id' ).bind('eventName', function(event){ code... });
$('element_id').click(function(){ code... });

2. Puzzle
The puzzle is like this. There is the following code snippet in the add page:
Copy code The code is as follows:


... ...


... ...






... ...



Following the above ideas, can anyone help me write the codes for hijack code 03 and hijack code 04? Or provide other solutions?
Following the above ideas, can anyone help me write the codes for hijack code 03 and hijack code 04? Or provide other solutions?
1. The existing code cannot be modified.
2. If possible, extending the original js class is also allowed.
3. func_test and not_existfunc are not known in advance and can only be obtained through "getting".
4. For the ultimate purpose, I need to know the error object, method name, event, and parameters where the error occurred. Based on this purpose, other solutions are also possible.
5. Client-side debugging tools such as firebug cannot be used. Let this type of tool tell you "the code is wrong".
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn