我试图在点击下一页中的箭头时添加一些要执行的操作:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript">
function createActions() {
var div = document.getElementById("l");
div.onclick=function(){alert("HI")};
}
window.onload = createActions;
</script>
</head>
<body>
<math>
<mn>12</mn>
<mo>×<!-- × --></mo>
<mi>a</mi>
<munderover>
<mo>=</mo>
<mo id="l" style="color: red;">→</mo>
<mo style="color: red;">←</mo>
</munderover>
<mi>24</mi>
</math>
</body>
</html>
&#13;
调试器显示元素&#34; l&#34;通过调用&#34; getElementById&#34;返回,但&#34; onclick&#34;的定义。属性什么都不做。
除了之前的测试,我还测试了没有javascript和mathml:
<mo onclick='alert("HI")'>→</mo>
也没有成功。
答案 0 :(得分:2)
count = 1;
document.getElementById("l").addEventListener("click", function(){
alert("You clicked "+ count++ +" times");
});
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<math>
<mn>12</mn>
<mo>×<!-- × --></mo>
<mi>a</mi>
<munderover>
<mo>=</mo>
<mo id="l" style="color: red;">→</mo>
<mo style="color: red;">←</mo>
</munderover>
<mi>24</mi>
</math>
</body>
</html>