OnClick突然不适用于Chrome中的Google协作平台 [英] OnClick suddenly not working on Google Sites in Chrome

查看:168
本文介绍了OnClick突然不适用于Chrome中的Google协作平台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个使用onclick按钮的页面来调用一个函数,作为我的学生练习问题和答案的一部分。它从7月份开始工作,至少在9月5日星期五之前没有问题。今天这些按钮在Chrome中根本无法正常工作,我无法弄清楚为什么在我的生活中。他们继续在IE中正常运行。

我已经发布了我可以编写的最简单的代码,这在下面不会起作用。这非常简单,说实话我觉得很好。这似乎工作,如果我把整个东西粘贴到JSFiddle的HTML框中,但如果我尝试分离脚本,它不会做任何事情。我不知道这是因为它是坏的,还是因为我将它分开了。



我在尝试调试时遇到问题,主要是因为Google协作平台完全重写你的工作变成了自己的格式,这些格式或多或少都是不可读的,而不是由硅制成的。当我加载并尝试点击时,我确实收到一个异常:

 未捕获错误:不应该发生:ES5 / 3传递给makeDOMAccessible的对象

但是我已经完全没有计算出发生了什么的运气,这甚至是真正的问题。



我已阅读了很多关于Google站点被Javascript挑剔的内容,但我不知道问题是否与站点或者Chrome或者两者结合在一起或者是什么,但是这是我想要解决的问题,因为大部分学生和我主要使用Chrome。



全部下面的代码将按插入HTML格式插入,仅供参考。



如果事实证明这是重复的,我搜索了一段时间,并找不到解决方案。

 < html> 
< body>
< button onclick =Check()> Push Me< / button>

< script>
函数Check(){
alert(It worked);
}
< / script>

< / body>
< / html>

对于修复我所得到的任何建议(如果它甚至被破坏)或者直接重做我们欢迎与网站和Chrome一起使用的方式。提前致谢。



这是一个以前在Chrome中工作的完整页面,不再是。当你按下各个按钮时,它显示了一个表格的行。



编辑:这似乎适用于较旧版本的Chrome。我想我需要在这个问题上打开Chrome论坛。

解决方案

epapearello提供的解决方法是使用addEventListener代替onclick事件,似乎工作。我仍然无法获得我的示例中的警告窗口,因为某些原因(针对Google协作平台的政策?)工作,但是我想要的实际功能(设置段落对象的innerHTML)正常工作。



这似乎是Google协作平台与Chrome v.37之间的一个问题。希望它在不久的将来得到解决。



以下是一个正常工作的等效代码示例。

 < HTML> 
< body>

< button id =AnswerButton1>检查答案1< / button>

< p id =Answer1>< / p>

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

函数Answer(n){
document.getElementById(Answer+ n).innerHTML =对数字1的回答;
}

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

感谢那些帮助过的人。

I wrote a page that used buttons with onclick to call a function as part of a set of practice problems and answers for my students. It has worked since July with no issues through Friday, September 5 at least. Today the buttons fail to function at all in Chrome, and I can't figure out why for the life of me. They do continue to function properly in IE.

I've posted the simplest code I could write that won't work below. It's awfully simple, and honestly I think it's fine. It seems to work if I paste the entire thing into JSFiddle's HTML box, but if I try to separate the script it doesn't do anything. I don't know whether that's because it's broken or because I am separating it incorrectly though.

I'm having trouble trying to debug it, largely because Google Sites completely rewrites your work into its own format which is more or less unreadable without being made of silicon. When I load this and try to click, I do get an exception:

Uncaught Error: shouldn't happen: ES5/3 object passed to makeDOMAccessible

But I have had absolutely no luck with figuring out what is happening there, or whether that is even really the problem or not.

I've read a lot about Google Sites being picky with Javascript, and I don't know whether the issue is with Sites or Chrome or the two together or what, but it's something that I'd like to get sorted out, as the bulk of my students and I primarily use Chrome.

All of the code below is going into an inserted HTML box as written, just FYI.

Apologies if this turns out to be a duplicate; I searched for quite a while and couldn't find a solution.

<html>
<body>
<button onclick="Check()">Push Me</button>

<script>
function Check() {
    alert("It worked");
}
</script>

</body>
</html>

Any suggestions for fixing what I've got (if it's even broken) or redoing it in a straightforward way that would work with Sites and Chrome would be welcome. Thanks in advance.

Here is one full page that was working previously in Chrome and is no longer. It displayed the rows of a table as you pressed the various buttons.

EDIT: This appears to work in older versions of Chrome. I guess I need to hit up the Chrome forums with this issue.

解决方案

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.

这篇关于OnClick突然不适用于Chrome中的Google协作平台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆