在GWT/Bootstrap中设置数据属性 [英] Setting data- attribute in GWT / Bootstrap

查看:131
本文介绍了在GWT/Bootstrap中设置数据属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与GWT合作,并通过GWT-Bootstrap库实施引导程序.

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

我似乎找不到找到将data-attribute属性添加到元素的方法吗?

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

我可以通过直接编写HTML来做到这一点:

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

但这很丑陋,无法达到使用GWT的目的(最好编写纯HTML代码).

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

推荐答案

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

这篇关于在GWT/Bootstrap中设置数据属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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