7

如何将自定义图像添加到 dojo 按钮

这是没有图像的按钮的示例代码

<div id="zoomin" data-dojo-type="dijit.form.Button">
    <span>zoomin</span>
</div>
4

4 回答 4

11

这些答案很接近,但您的图标的样式定义必须包括以下内容:

.myIcon {
  background-image: url(...);
  background-repeat: no-repeat;
  width: 16px;
  height: 16px;
  text-align: center;
}
于 2012-10-26T20:46:10.670 回答
6

您可以在小部件上设置图标类,然后在 css 中提供图像。

<div id="zoomin" data-dojo-type="dijit.form.Button" iconClass="myIcon">
    <span>zoomin</span>
</div>

.myIcon {
  background-image:  url(...);
}

http://dojotoolkit.org/reference-guide/1.7/dijit/form/Button.html#change-the-icon

于 2012-06-11T20:13:28.627 回答
1

遵循克雷格的回答,但要符合 1.7+ 和 html 标准,而是使用

<div id="zoomin" data-dojo-type="dijit.form.Button" data-dojo-props="iconClass:'myIcon'">
    <span>zoomin</span>
</div>

或者您可以通过函数覆盖来决定哪个

<div id="zoomin" data-dojo-type="dijit.form.Button">
    <script type="dojo/method" data-dojo-event="getIconClass">
         var regular = this.inherited(arguments);
         // this evaluation will allways be true, but here for sake of argument
         return (this.declaredClass == 'dijit.form.Button' ? "myButtonIcon" : regular);
    </script>
    <span>zoomin</span>
</div>
于 2012-06-12T10:49:21.370 回答
0

我使用 dojo 1.10 并使用 usingbackground-repeat:round

<div id="zoomin" data-dojo-type="dijit/form/Button" iconClass="myIcon">
<span>zoomin</span>

.myIcon {
 background-image:  url(...);
 background-repeat: round;
 width: 18px;
 height: 18px;
 text-align: center;
}
于 2017-12-21T13:02:05.513 回答