JavaScriptisDOM-如何检查JavaScript对象是否是DOM对象?
document.createElement('div') //=> true{tagName: 'foobar something'} //=> false
tagName
if (!object.tagName) throw ...;
function isDOM(obj) { var tag = obj.tagName; try { obj.tagName = ''; // Read-only for DOM, should throw exception obj.tagName = tag; // Restore for normal objects return false; } catch (e) { return true; }}
慕容3067478
相关分类