删除click事件off()后如何使用on()? [英] How to use on() after removing the click event off()?
本文介绍了删除click事件off()后如何使用on()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
off()正在删除点击事件句柄.
off() is removing the click event handle.
on()应该重新绑定效果,但是不起作用
on() was supposed to rebind the effect, but is not working
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('p').on('click', function(){
$(this).css('color', 'blue');
});
$('#btn_off').click(function(){
$('p').off('click');
});
$('#btn_on').click(function(){
$('p').on('click');
});
});
</script>
<span>Click the paragraph:</span>
<p>Prg #1</p>
<p>Prg #2</p>
<p>Prg #3</p>
<p>Prg #4</p>
<button id="btn_off">bind off prg.</button>
<button id="btn_on">bind on prg.</button>
在标题中查看我的问题.
See my question in the title.
推荐答案
绑定事件时您没有传递点击处理程序.
You are not passing the click handler while bind event.
使用
$(document).ready(function(){
//Declare click handler
var pClickHandler = function(){
$(this).css('color', 'blue');
}
//Bind click handler on document ready
$('p').on('click', pClickHandler);
$('#btn_on').click(function(){
//Bind click handler on on click
$('p').on('click', pClickHandler);
});
});
这篇关于删除click事件off()后如何使用on()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文