Setting data- attribute in GWT / Bootstrap

北战南征 提交于 2019-12-07 17:20:11

问题


I am working with GWT and implementing bootstrap through GWT-Bootstrap library.

I can't seem to find a way to add data- attributes to my elements?

I can do it by writing HTML directly:

HTMLPanel htmlPanel = new HTMLPanel("<button type=\"button\" class=\"btn\" data-custom=\"some-custom-data\">Hello World</button>");
menuControl.add(htmlPanel);

But that's just ugly and defeat the purpose of using GWT (might as well write a plain HTML code).

I am looking for ways to do something like:

Button button = new Button();
button.setText("Hello World");
button.setStyleName("btn");
// Fine up to here, but now i want:
button.setAttr("data-custom", "some-custom-data");

回答1:


How about button.getElement().setAttribute("data-custom","some-custom-data"); ?



来源:https://stackoverflow.com/questions/18059907/setting-data-attribute-in-gwt-bootstrap

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