OnClick suddenly not working on Google Sites in Chrome

梦想的初衷 提交于 2019-12-05 04:51:31

The workaround suggested by epascarello, using addEventListener in place of onclick events, seems to work. I still can't get the alert window in my example to work for some reason (against Sites policy?), but the actual functionality I wanted, setting the innerHTML of a paragraph object, is working properly.

This appears to be an issue between Google Sites and Chrome v.37. Hopefully it is resolved in the near future.

Here is an example of equivalent code that is working correctly.

<html>
<body>

<button id="AnswerButton1">Check Answer 1</button>

<p id="Answer1"></p>

<script>
    document.getElementById("AnswerButton1").addEventListener("click",function(){Answer(1);});

    function Answer(n){
        document.getElementById("Answer"+n).innerHTML = "Answer to Number 1";
    }  

</script>
</body>
</html>

Thanks to those who helped.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!