按钮 btn
btn() 生成按钮。用 btnType 设置表单行为,用 type 设置外观。样式示例见 ZUI 按钮。
简单使用
php
btn('保存');html
<button class="btn" type="button">
<span class="text">保存</span>
</button>按钮外观类型
通过 type 属性设置按钮外观类型,可选值为 'default'、'primary'、'success'、'info'、'warning'、'danger'、'link'。
php
btn
(
set::type('primary'),
'保存'
);html
<button class="btn primary" type="button">
<span class="text">保存</span>
</button>包含链接
通过 url 属性设置按钮链接,此时按钮会自动使用 <a> 元素进行渲染。
php
btn
(
set::url('https://openzui.com'),
'打开 ZUI 网站'
);html
<a class="btn btn-default" href="https://openzui.com">
<span class="text">打开 ZUI 网站</span>
</a>包含图标
通过 icon 属性设置按钮图标,使用 trailingIcon 设置末尾图标。
php
btn
(
set::icon('home'),
'首页'
);html
<button class="btn" type="button">
<i class="icon icon-home"></i>
<span class="text">首页</span>
</button>属性
| 名称 | 类型 | 可选 | 声明默认值 | 说明 |
|---|---|---|---|---|
text | string | 是 | — | 按钮的文本。 |
textClass | string | 是 | — | 按钮文本的样式类。 |
icon | string | 是 | — | 图标名称。 |
iconClass | string | 是 | — | 图标的样式类。 |
square | bool | 是 | — | 是否为方形按钮,通常用于只显示一个图标的按钮。 |
disabled | bool | 是 | — | 是否禁用按钮。 |
active | bool | 是 | — | 是否为激活状态。 |
url | string | 是 | — | 按钮的链接地址。 |
target | string | 是 | — | 按钮的链接目标。 |
size | stringint | 是 | — | 按钮的尺寸,可选值为 'xl'、'lg'、'md'、'sm' 或者通过数字设置宽高,如 20。 |
trailingIcon | string | 是 | — | 按钮尾部图标的名称。 |
trailingIconClass | string | 是 | — | 按钮尾部图标的样式类。 |
caret | stringbool | 是 | — | 按钮的下拉箭头,可选值为 'top'(向上)、'bottom'(向下) 或者 true(自动)。 |
hint | string | 是 | — | 按钮的提示文本(鼠标悬停时显示)。 |
type | string | 是 | — | 按钮的类型,可选值为 'default'、'primary'、'success'、'info'、'warning'、'danger'、'link'。 |
btnType | string | 是 | "button" | 按钮的类型,可选值为 'button'、'submit'、'reset'。 |