1. In actual work, everyone can write various assignment statements.
For example, the most commonly used = "none";
If there are too many assignment statements like this, it will be dizzy if you line up them up
The extend function in my below allows the assignment of attributes or even function handles in json format
/**
* Extended function
* @param target Object that needs to be extended
* @param params properties and methods to put into target
*/
function extend(target, params) {
if (!target) {
target = {};
}
for (var prop in params) {
target[prop] = params[prop];
}
return target;
}
2. Since I do not fully comply with the W3C standard, its event model is different from other browsers.The methods called are also different.
If you encounter an event that you want to dynamically add to the control. Using onclick = function() {}, such as dom, may not be valid when dynamically created, and multiple handles cannot be bound. The following is a common binding event function that supports the entire browser.
In most cases, useCapture uses false, so I'll just write it to death here.
/**
* Dynamically create event handles
* @param control Objects that need to be extended
* @param eventName Event Name
* @param fn function handle
*/
function addEventListener(control, eventName, fn) {
if () {
('on' + eventName, fn);
} else {
(eventName, fn, false);
}
}
The above two functions can be used to refer to the code in other articles I wrote.
For example, the most commonly used = "none";
If there are too many assignment statements like this, it will be dizzy if you line up them up
The extend function in my below allows the assignment of attributes or even function handles in json format
Copy the codeThe code is as follows:
/**
* Extended function
* @param target Object that needs to be extended
* @param params properties and methods to put into target
*/
function extend(target, params) {
if (!target) {
target = {};
}
for (var prop in params) {
target[prop] = params[prop];
}
return target;
}
2. Since I do not fully comply with the W3C standard, its event model is different from other browsers.The methods called are also different.
If you encounter an event that you want to dynamically add to the control. Using onclick = function() {}, such as dom, may not be valid when dynamically created, and multiple handles cannot be bound. The following is a common binding event function that supports the entire browser.
In most cases, useCapture uses false, so I'll just write it to death here.
Copy the codeThe code is as follows:
/**
* Dynamically create event handles
* @param control Objects that need to be extended
* @param eventName Event Name
* @param fn function handle
*/
function addEventListener(control, eventName, fn) {
if () {
('on' + eventName, fn);
} else {
(eventName, fn, false);
}
}
The above two functions can be used to refer to the code in other articles I wrote.