简体   繁体   English

从gwt对话框标题中删除样式

[英]Remove style from gwt dialogbox header

How to remove dependent styles? 如何删除依赖样式?

In GWT dialog box, I need to remove the style .dialogtopleft from .gwt-Dialogbox . dialogtopleft 在GWT对话框,我需要删除的样式.dialogtopleft.gwt-Dialogbox . dialogtopleft .gwt-Dialogbox . dialogtopleft . .gwt-Dialogbox . dialogtopleft

How to remove it? 如何将其删除?

You would need jQuery to do that easily. 您将需要jQuery轻松做到这一点。 You can find some jQuery wrappers for GWT, but you can also do it using plain DOM traversal. 您可以找到一些GWT的jQuery包装器,但也可以使用普通的DOM遍历来实现。

I have a small recursive method to find element by given class name. 我有一个小的递归方法,可以通过给定的类名查找元素。 It returns the first element found or null. 它返回找到的第一个元素或为null。

public Element findChildElementByClassName(Element parent, String className) {
    List<String> classNames = Arrays.asList(parent.getClassName().split(" "));
    if(classNames.contains(className))
        return parent;
    else {
        Element foundElement = null;
        NodeList<Node> childNodes = parent.getChildNodes();
        for(int i = 0; i < childNodes.getLength() && foundElement == null; i++)
            if(childNodes.getItem(i).getNodeType() == Node.ELEMENT_NODE) {
                Element childElement = (Element) childNodes.getItem(i);
                foundElement = findChildElementByClassName(childElement, className);
            }

        return foundElement;
    }
}

I hope it's self explaining, but you need to notice that node type must be checked before casting it to an element. 我希望它可以自我解释,但是您需要注意,在将节点类型转换为元素之前必须检查该节点类型。

You should use it this way: 您应该以这种方式使用它:

DialogBox dialogBox = new DialogBox();
// ... initialize dialogBox
dialogBox.show();

Element dialogTopLeftElement = findChildElementByClassName(dialogBox.getElement(), "dialogTopLeft");
if(dialogTopLeftElement != null)
    dialogTopLeftElement.removeClassName("dialogTopLeft");

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

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