jQuery基础06

HTML部分

<div id="div1"></div>

CSS部分

        <style type="text/css">
			#div1 {
				width: 200px;
				height: 200px;
				background-color: red;
			}
		</style>

JQ事件

1. jq对象.事件名(回调函数)     例 $("选择器").click(function(){})

2. jq对象.on("事件名",回调函数)   JQ推荐的事件绑定方式

基础写法 语法: $().on("事件名", "回调函数");

            // 随机色函数
            function randomClolor() {
				var r = Math.floor(Math.random() * 256);
				var g = Math.floor(Math.random() * 256);
				var b = Math.floor(Math.random() * 256);
				return `rgb(${r},${g},${b})`;
			}
$("#div1").on("click",function(){
	$(this).css("background",randomClolor());
});

2. 一次性绑定多个不同事件

语法: $().on("事件名1 事件名2 事件名3 ...")

$("#div1").on("mousemove mouseout click",function(){
	$(this).css("background",randomClolor())
})

3. 一次性绑定多个不同事件, 不同事件触发各自的方法

// 语法:
$().on({
    事件名1:回调函数1,
    事件名2:回调函数2,
    ...
})

$("#div1").on({
	onmouseover:function(){
		$(this).animate({
			height:"+=10"
		})
	},
	mouseout:function(){
		$(this).animate({
			width:"+=10"
	    })
    },
		click:function(){
			$(this).css("background",randomClolor());	
		},	
/});

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值