我想打印isChecked
的属性:
<!DOCTYPE html>
<html>
<head>
<script>
function myFunction(){
alert(document.getElementById('myId').isChecked);
}
</script>
</head>
<body>
<img id="myId" isChecked="0"/>
<br>
<button onclick="myFunction();">Click me</button>
</body>
</html>
它会打印我undefined
任何帮助表示赞赏!
答案 0 :(得分:9)
alert(document.getElementById('myId').getAttribute("isChecked"));
答案 1 :(得分:1)
试试,
alert(document.getElementById('myId').getAttribute("isChecked"));