在网页设计过程中,经常遇见按钮的各状态效果。写了一个jquery扩展,使这个过程更方便!
使用前注意引用Jquery;
JqueryExtend.js:
复制代码 代码如下:
(function ($) {
// Button按钮的三种样式替换,如果isState参数为True则记录按下状态
$.fn.btnEffect = function (normal, mouseover, mousedown, isState) {
var lastButton;
this.each(function () {
$(this).bind({
mouseover: function () {
if (this != lastButton || !isState) {
$(this).removeClass().addClass(mouseover)
}
},
mouseout: function () {
if (this != lastButton || !isState) {
$(this).removeClass().addClass(normal)
}
},
mousedown: function () {
if (this != lastButton || !isState) {
if (lastButton != null) {
$(lastButton).removeClass().addClass(normal);
}
$(this).removeClass().addClass(mousedown);
lastButton = this;
}
}
});
});
}
})(jQuery);
示例页面Default.aspx:
复制代码 代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="JqueryExtend_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="/UploadFiles/2021-04-02/jquery-1.7.1.js"><script src="JqueryExtend.js"><style type="text/css">
.btn
{
border: 0px;
background: red;
}
.btn1
{
border: 0px;
background: green;
}
.btn2
{
border: 0px;
background: yellow;
}
</style>
<script type="text/javascript">
$().ready(function () {
$("#aa,#bb").btnEffect("btn", "btn1", "btn2", true);
$("#cc").btnEffect("btn", "btn1", "btn2", false);
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="aa" class="btn" type="button" value="按钮1" />
<input id="bb" class="btn" type="button" value="按钮2" />
<input id="cc" class="btn" type="button" value="按钮3" />
</div>
</form>
</body>
</html>
使用前注意引用Jquery;
JqueryExtend.js:
复制代码 代码如下:
(function ($) {
// Button按钮的三种样式替换,如果isState参数为True则记录按下状态
$.fn.btnEffect = function (normal, mouseover, mousedown, isState) {
var lastButton;
this.each(function () {
$(this).bind({
mouseover: function () {
if (this != lastButton || !isState) {
$(this).removeClass().addClass(mouseover)
}
},
mouseout: function () {
if (this != lastButton || !isState) {
$(this).removeClass().addClass(normal)
}
},
mousedown: function () {
if (this != lastButton || !isState) {
if (lastButton != null) {
$(lastButton).removeClass().addClass(normal);
}
$(this).removeClass().addClass(mousedown);
lastButton = this;
}
}
});
});
}
})(jQuery);
示例页面Default.aspx:
复制代码 代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="JqueryExtend_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="/UploadFiles/2021-04-02/jquery-1.7.1.js"><script src="JqueryExtend.js"><style type="text/css">
.btn
{
border: 0px;
background: red;
}
.btn1
{
border: 0px;
background: green;
}
.btn2
{
border: 0px;
background: yellow;
}
</style>
<script type="text/javascript">
$().ready(function () {
$("#aa,#bb").btnEffect("btn", "btn1", "btn2", true);
$("#cc").btnEffect("btn", "btn1", "btn2", false);
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="aa" class="btn" type="button" value="按钮1" />
<input id="bb" class="btn" type="button" value="按钮2" />
<input id="cc" class="btn" type="button" value="按钮3" />
</div>
</form>
</body>
</html>
标签:
jquery,按钮状态
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com
暂无“jquery 按钮状态效果 正常、移上、按下”评论...