jQuery UI 按钮是基于 jQuery UI 框架的交互式按钮组件,它提供了标准化的外观和行为,可以轻松地创建一致的用户界面元素。
jQuery UI 按钮默认使用 jQuery UI 主题,可以通过以下方式更改:
// 初始化按钮
$("#myButton").button();
// 通过CSS覆盖样式
.ui-button {
background: #ff9900;
border: 1px solid #e68a00;
color: white;
font-weight: bold;
}
jQuery UI 按钮支持内置图标,可以通过以下方式修改:
$("#myButton").button({
icons: {
primary: "ui-icon-gear", // 主图标
secondary: "ui-icon-triangle-1-s" // 次图标(可选)
}
});
$("#toggleButton").button({
icons: { primary: "ui-icon-check" }
}).click(function() {
$(this).toggleClass("ui-state-active");
});
.ui-button.ui-state-active {
background: #0066cc;
border-color: #0055aa;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<style>
.custom-button {
background: linear-gradient(to bottom, #ff9900, #e68a00);
border: 1px solid #cc7a00;
color: white;
text-shadow: 0 1px 0 #995c00;
}
.custom-button.ui-state-active {
background: linear-gradient(to bottom, #0066cc, #0055aa);
border-color: #004488;
}
</style>
</head>
<body>
<button id="myButton">普通按钮</button>
<button id="iconButton">带图标按钮</button>
<button id="toggleButton">开关按钮</button>
<script>
$(function() {
// 普通按钮
$("#myButton").button().addClass("custom-button");
// 带图标按钮
$("#iconButton").button({
icons: {
primary: "ui-icon-star"
}
});
// 开关按钮
$("#toggleButton").button({
icons: { primary: "ui-icon-check" }
}).click(function() {
$(this).toggleClass("ui-state-active");
});
});
</script>
</body>
</html>
通过以上方法,您可以灵活地自定义 jQuery UI 按钮的外观和行为,满足各种界面设计需求。
没有搜到相关的文章