如何确定HTML元素是否具有“value”属性/属性?
文本区域示例:
let textarea = document.createElement("textarea");
textarea.innerHTML = "Sike!";
console.log(textarea.hasAttribute("value")); // returns false (expected true)
console.log(textarea.hasOwnProperty("value")); // returns false (expected true)
console.log(textarea.value); // returns "Sike!";
DIV实例:
let div = document.createElement("div");
div.innerHTML = "Sike!";
console.log(div.hasAttribute("value")); // returns false (expected false)
console.log(div.hasOwnProperty("value")); // returns false (expected false)
console.log(div.value); // returns undefined; (expected thrown error)