jQuery学习19---事件中bind与unbind

时间:2022-08-26 10:09:55


<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=GBK">
<title></title>
<script src="../jquery-1.8.2.js" type="text/javascript"></script>
<style type="text/css">
</style>
<script type="text/javascript">
$(function()
{
$(":button[value=bind]").click(function()
{
//绑定单击事件
/*
$("#test").bind("click",function()
{
alert("click");
});
*/
//绑定多个事件
/*
$("#test").bind({"click":function()
{
alert("click");
},"mouseover":function()
{
alert("mouseover");
},"mouseout":function()
{
alert("mouseout");
}});
*/
});

$(":button[value=unbind]").click(function()
{
//移除指定事件
$("#test").unbind("mouseover");
//移除所有的事件
$("#test").unbind();
});
});
</script>
</head>
<body>
<input id="test" type="button" value="test" /><br />
<input type="button" value="bind" /><br />
<input type="button" value="unbind" /><br />
</body>
</html>