gpt4 book ai didi

gwt - 在 GWT/Bootstrap 中设置数据属性

转载 作者:行者123 更新时间:2023-12-04 02:49:30 25 4
gpt4 key购买 nike

我正在使用 GWT 并通过 GWT-Bootstrap 库实现 Bootstrap 。

我似乎找不到向我的元素添加数据属性的方法?

我可以通过直接编写 HTML 来实现:

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

但这很丑陋并且违背了使用 GWT 的目的(还不如编写一个纯 HTML 代码)。

我正在寻找方法来做类似的事情:

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");

最佳答案

怎么样 button.getElement().setAttribute("data-custom","some-custom-data");

关于gwt - 在 GWT/Bootstrap 中设置数据属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18059907/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com