<!doctype html><html>
<head>
<meta charset=
"utf-8"
>
<title>jQuery基本操作事件绑定</title>
<script type=
"text/javascript"
src=
"js/jquery-1.7.js"
> </script>
<style type=
"text/css"
>
p{width:200px;height:200px;border:1px solid #666;}
#leftp{float:left; margin:0 auto;}
#rightp{float:right;}
</style>
</head>
<body>
<p id=
"leftp"
>
<input type=
"button"
value=
"bind事件绑定"
id=
"bindBtn"
/>
<input type=
"button"
value=
"多事件绑定"
id=
"manyBindBtn"
/>
<input type=
"button"
value=
"delegate事件绑定"
id=
"delegateBindBtn"
/>
<input type=
"button"
value=
"解除事件绑定"
id=
"removeBindBtn"
/>
</p>
<p id=
"rightp"
>右侧展示区</p>
<script type=
"text/javascript"
>
$(
function
(){
$(
"#manyBindBtn"
).bind({
click:
function
(){$(
"#rightp"
).slideToggle();},
mouseover:
function
(){$(
"#rightp"
).css(
"background-color"
,
"red"
);},
mouseout:
function
(){$(
"#rightp"
).css(
"background-color"
,
"yellow"
);}
});
$(document).delegate(
"#delegateBindBtn"
,
"click"
,
function
(){
$(
"#rightp"
).slideToggle();
});
$(
"#rightp"
).hover(
function
(){
$(this).css(
"background-color"
,
"gray"
);
},
function
(){
$(this).css(
"background-color"
,
"white"
);
});
$(
"#leftp"
).on(
"click"
,
"#bindBtn"
,
function
(){
alert(
"使用bind()方法绑定事件处理"
);
});
$(
"#removeBindBtn"
).on(
"click"
,
function
(){
$(
"#manyBindBtn"
).off(
"click"
);
$(document).off(
"click"
,
"#delegateBindBtn"
);
$(
"#leftp"
).off(
"click"
,
"#bindBtn"
);
$(
"input[type=button]"
).off();
});
});
</script>
</body></html>