如何将自定义图像添加到道场按钮
这是没有图像的按钮的示例代码
<div id="zoomin" data-dojo-type="dijit.form.Button">
<span>zoomin</span>
</div>
答案 0 :(得分:11)
这些答案很接近,但图标的样式定义必须包含以下内容:
.myIcon {
background-image: url(...);
background-repeat: no-repeat;
width: 16px;
height: 16px;
text-align: center;
}
答案 1 :(得分: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
答案 2 :(得分: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>
答案 3 :(得分: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;
}