我正在尝试检查一个元素的值,但它返回 undefined
虽然它在我检查它的类时有效。
HTML:
<div class='cube' value='test' onclick='checkCube(this)'></div>
JavaScript:
function checkCube(cube) { // - there's either one of those lines, not both)
var check = cube.value; //This is not working,
var check = cube.className; //This is.
console.log(check);
}
最佳答案
value
属性仅支持输入元素
对非输入元素使用getAttribute
var check = cube.getAttribute("value");
关于javascript - 获取元素的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47905200/