访问和修改“HTMLInputElement.<property>”是否比“Element”更快.(g/s)etAttr

Is access and modification of 'HTMLInputElement.<property>' faster than "Element.(g/s)etAttribute('<property>')"?

本文关键字:更快 etAttr Element 修改 property 是否 访问 HTMLInputElement      更新时间:2023-09-26

例如,如果我想检查输入元素是否被禁用,什么会更快?

//assuming node is an <input> element
var a = node.getAttribute('disabled');
//or
var a = node.disabled;

同样,如果我想更改值,

//assuming node is an <input> element
node.setAttribute('disabled', true);
//or 
node.disabled = true;
//(Both change the DOM node)

本机访问是一种最快的方法,因为不执行兼容性导航器检查。在您的情况下,禁用属性是在著名的导航器中定义的,但可以未定义"特殊"事件或属性。

因此,如果您想要拥有最快/性能的解决方案,请尝试避免框架属性/事件访问并使用特定的本机脚本。