JS如何通过元素的CLASS属性得到对应的DOM对象
发布网友
发布时间:2022-04-29 19:10
我来回答
共2个回答
热心网友
时间:2022-04-22 15:24
<html>
<head>
<meta
http-equiv="Content-type"
content="text/html;
charset=utf-8">
<title>1</title>
</head>
<script
type="text/javascript"
charset="utf-8">
window.onload=function()
{
document.getElementsByClassName('aaa')[0].innerHTML="sdf"
}
</script>
<body>
<div
class="aaa">
</div>
</body>
</html>
是getElementsByClassName,你少个s
firefox、Opera浏览器下测试通过
热心网友
时间:2022-04-22 16:42
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>1</title>
</head>
<script type="text/javascript" charset="utf-8">
window.onload=function() {
document.getElementsByClassName('aaa')[0].innerHTML="sdf"
}
</script>
<body>
<div class="aaa">
</div>
</body>
</html>
是getElementsByClassName,你少个s
firefox、Opera浏览器下测试通过