jQuery事件

1、ready()事件

在文档加载完成后激活函数;

$(document).ready(function(){
  $(".btn1").click(function(){
    $("p").slideToggle();
  });
});

2、keydown()方法

$('#password').keydown(function(){
    if (event.keyCode ==13) {
        $('#login').trigger('click');
    };
});

3、resize()方法

当调整浏览器窗口大小时,触发resize事件。

$(window).resize(function(){
	var width  = $(window).width() - $('#left').outerWidth() - $('.dl-second-slib-con').outerWidth();
	var height = $(window).height() - $('#head').outerHeight();
	$('#left').outerHeight(height);
	$('#right').outerHeight(height);
	$('#right').outerWidth(width);
}).trigger('resize');

4、delegate()方法
<p style="margin-top: 12px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; line-height: 18px; font-family: Verdana, Arial, 宋体; background-color: rgb(249, 249, 249);">delegate() 方法为指定的元素(属于被选元素的子元素)添加一个或多个事件处理程序,并规定当这些事件发生时运行的函数。使用 delegate() 方法的事件处理程序适用于当前或未来的元素(比如由脚本创建的新元素)。</p>
<pre name="code" class="javascript">$('div').delegate('#audit','click',function(){
	alert($(this).val());	
})



5、on()方法

var audit = $('div').on('click','#audit',function(){
	console.log(123);	
})
on()方法和delegate()方法可以用于动态页面的点击事件,如果div是包含两层的,会执行两次事件,所以最好用类来缩小范围。如下:

$('.content-data').on('click','#audit',function(){
	console.log(123);	
})




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值