简体   繁体   English

Chrome:更改className属性不适用于GWT

[英]Chrome: className attribute changing not working with GWT

I have a site written in GWT. 我有一个用GWT编写的网站。 I need to change style of some element by clicking on this element. 我需要通过单击此元素来更改某些元素的样式。 I'm using code like this: 我正在使用这样的代码:

image.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
  ...............
        Element element = ((Image) event.getSource()).getElement();
        element.setClassName("new_css_class_to_be_applied");
       }

'setClassName' GWT function uses className JavaScript property to operate with class: 'setClassName'GWT函数使用className JavaScript属性对类进行操作:

   public final native void setClassName(String className) /*-{
       this.className = className;
    }-*/;

This code changes a class name of element (I can see the new class name in the DOM inspector) but styles from the class do not apply to the element. 这段代码更改了元素的类名(我可以在DOM检查器中看到新的类名),但是类中的样式不适用于该元素。

This problem appears only in Chrome browser on Windows, with IE and Firefox it works well. 此问题仅出现在Windows上的Chrome浏览器中,并且与IE和Firefox兼容。

If I move folder with Chrome local settings ( C:\\Users\\User_name\\AppData\\Local\\Google\\Chrome\\ ) this problem disappears and style changing starts working correctly. 如果我使用Chrome本地设置(C:\\ Users \\ User_name \\ AppData \\ Local \\ Google \\ Chrome \\)移动文件夹,此问题将消失,样式更改将开始正常进行。 But if I return back previous chrome settings folder this code doesn't work again. 但是,如果我返回以前的chrome设置文件夹,此代码将无法再使用。 I have no any specific settings or plugins in Chrome, everything is default. 我在Chrome中没有任何特定设置或插件,所有内容均为默认设置。

It seems to be a bug in the Chrome browser but I don't find concrete preconditions how to reproduce it. 这似乎是Chrome浏览器中的错误,但我没有找到具体的前提条件来重现它。 I googled but didn't find the same problems and resolutions. 我用谷歌搜索,但没有找到相同的问题和解决方案。

Could anybody advice me any workaround for the problem? 有人可以建议我解决该问题吗?

UPD. UPD。 It was a problem with AdBlock Chrome extension. AdBlock Chrome扩展程序存在问题。 I disabled it and the problem disappeared.More details: https://code.google.com/p/chromium/issues/detail?id=377913 我禁用了它,问题消失了。更多详细信息: https : //code.google.com/p/chromium/issues/detail?id=377913

Try to create a simple html document without any JS library not GWT app and execute something like: 尝试创建一个没有任何JS库而不是GWT应用程序的简单html文档,然后执行以下操作:

 document.getElementById("MyElement").className = "MyClass";

If the problem persists open an issue to chrome. 如果问题仍然存在,请向chrome发送问题。

Also you can try the same in your GWT app using the developer console and see if it happens. 另外,您也可以使用开发者控制台在GWT应用程序中尝试相同的操作,看看是否会发生这种情况。

If you can demonstrate a procedure which can be repeatable by anyone for making it happe only in GWT open an issue in the GWT site. 如果您可以演示仅在GWT中使所有人感到高兴的任何人都可以重复的过程,请在GWT站点中打开一个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM