0
嘿家伙有人能解释为什么事件不执行? 调试器根本不会给出任何错误! 预先感谢您为什么事件没有执行?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<button class="boton">prueba</button>
<body>
<script type="text/javascript">
var elemento= document.getElementsByClassName("boton")
elemento.onclick=function(){
alert("hola");
};
debugger;
</script>
</body>
</html>
使用'var elemento = document.getElementsB yClassName(“boton”)[0]' –
[JavaScript上类的JavaScript点击事件监听器]的可能重复(http://stackoverflow.com/questions/19655189/javascript-click-event-listener-on-class) –
工作,非常感谢你! – ge00rge