如何将自定义图像添加到 dojo 按钮
这是没有图像的按钮的示例代码
<div id="zoomin" data-dojo-type="dijit.form.Button">
<span>zoomin</span>
</div>
这些答案很接近,但您的图标的样式定义必须包括以下内容:
.myIcon {
background-image: url(...);
background-repeat: no-repeat;
width: 16px;
height: 16px;
text-align: center;
}
您可以在小部件上设置图标类,然后在 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.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>
我使用 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;
}