Requirements Scenario:
It is sometimes necessary to judge whether a parameter is passed in as a DOM element, or if it is necessary to distinguish between a DOM or a non-dom element.
Example: An extension method MyMethod (domarg,optionsarg), parameters can be passed in (assuming that there are default processing internally), which makes sense for determining whether the parameter domarg is a DOM element.
The analysis code is as follows:
function Isdom (obj) {
vartypeof' object ' )? obj instanceof htmlelement : typeof' object 'typeof' String ';
further extension:
Sometimes the incoming object is not an obj, but a string (for example: Id\class, etc.), which is to preprocess the incoming parameters.
Judgment 1:
var temp=null;
if (typeof obj=== ' string ') {temp=$ (obj) [0];}
Judgment 2:
if (typeof obj=== ' object ') {tempobj=obj;}
Note that the above two judgements must be executed before the Isdom (obj) Method!
JavaScript determines if the parameter is a DOM element