jQuery-(3)事件

什么是事件?

页面对不同访问者的响应叫做事件。

  • 在元素上移动鼠标。
  • 选取单选按钮
  • 点击元素

常用的事件

(1)click()
click() 方法是当按钮点击事件被触发时会调用一个函数。

$("p").click(function(){
  $(this).hide();
});

(2)dblclick()
当双击元素时,会发生 dblclick 事件。

$("p").dblclick(function(){
  $(this).hide();
});

(3)mouseenter()
当鼠标指针穿过元素时,会发生 mouseenter 事件。

$("#p1").mouseenter(function(){
    alert('您的鼠标移到了 id="p1" 的元素上!');
});

(4)mouseleave()
当鼠标指针离开元素时,会发生 mouseleave 事件。

$("#p1").mouseleave(function(){
    alert("再见,您的鼠标离开了该段落。");
});

(5)mousedown()
当鼠标指针移动到元素上方,并按下鼠标按键时,会发生 mousedown 事件。

$("#p1").mousedown(function(){
    alert("鼠标在该段落上按下!");
});

(6)mouseup()
当在元素上松开鼠标按钮时,会发生 mouseup 事件。

$("#p1").mouseup(function(){
    alert("鼠标在段落上松开。");
});

(7)hover()
hover()方法用于模拟光标悬停事件。

$("#p1").hover(
    function(){
        alert("你进入了 p1!");
    },
    function(){
        alert("拜拜! 现在你离开了 p1!");
    }
);

(8)focus()
当元素获得焦点时,发生 focus 事件。

$("input").focus(function(){
  $(this).css("background-color","#cccccc");
});

(9)blur()
当元素失去焦点时,发生 blur 事件。

$("input").blur(function(){
  $(this).css("background-color","#ffffff");
});
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值