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

问题描述 投票:7回答:4

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

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

<div id="zoomin" data-dojo-type="dijit.form.Button">
    <span>zoomin</span>
</div>
html dojo
4个回答
11
投票

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

.myIcon {
  background-image: url(...);
  background-repeat: no-repeat;
  width: 16px;
  height: 16px;
  text-align: center;
}

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


1
投票

按照Craig的回答,但要符合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>

0
投票

我使用dojo 1.10并使用background-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;
}
© www.soinside.com 2019 - 2024. All rights reserved.