如何为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;
}
<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
请遵循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>
我使用的是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;
}
width: 16px;和height: 16px;
以使其正常工作。 - Richard Ayotte