Javascript 如何编写脚本以绑定和解除绑定以停止和启动单击事件
如何绑定(启用单击事件)和解除绑定(停止单击事件)jquery accordian取决于条件。如果我从下拉框中选择值1,我想启用第三链接accordian如果我选择值2,我想解除绑定第三个accordian。如何操作 脚本:Javascript 如何编写脚本以绑定和解除绑定以停止和启动单击事件,javascript,jquery,Javascript,Jquery,如何绑定(启用单击事件)和解除绑定(停止单击事件)jquery accordian取决于条件。如果我从下拉框中选择值1,我想启用第三链接accordian如果我选择值2,我想解除绑定第三个accordian。如何操作 脚本: //On click any <h3> within the container $('#container h3').click(function(e) { //Close all <div> but the <div> right
//On click any <h3> within the container
$('#container h3').click(function(e) {
//Close all <div> but the <div> right after the clicked <a>
$(e.target).next('div').siblings('div').slideUp('fast');
//Toggle open/close on the <div> after the <h3>, opening it if not open.
$(e.target).next('div').slideToggle('fast');
});
$('#status').on('change',function(){
if( $(this).val() == 1 ){
$('.text').bind('click');
}
if( $(this).val() == 2 ){
$('.text').unbind('click');
}
});
//单击容器中的任意
$(“#容器h3”)。单击(函数(e){
//单击鼠标右键后,关闭除右键以外的所有选项
$(e.target.next('div')。同胞('div')。slideUp('fast');
//在后切换打开/关闭,如果未打开则打开。
$(e.target).next('div').slideToggle('fast');
});
$('#status')。在('change',function()上{
if($(this).val()==1){
$('.text').bind('click');
}
if($(this).val()==2){
$('.text')。取消绑定('click');
}
});
您好,您可以使用“开”或“关”来启用单击功能
//On click any <h3> within the container
$('#container h3').click(function(e) {
//Close all <div> but the <div> right after the clicked <a>
$(e.target).next('div').siblings('div').slideUp('fast');
//Toggle open/close on the <div> after the <h3>, opening it if not open.
$(e.target).next('div').slideToggle('fast');
});
$('#status').on('change',function(){
console.log("status changed :" + $(this).val());
if($(this).val() == 1 ){
$('#container h3').on('click',function(e) {
//Close all <div> but the <div> right after the clicked <a>
$(e.target).next('div').siblings('div').slideUp('fast');
//Toggle open/close on the <div> after the <h3>, opening it if not open.
$(e.target).next('div').slideToggle('fast');
});
}
if($(this).val() == 2 ){
$('#container h3').off('click');
}
});
//单击容器中的任意
$(“#容器h3”)。单击(函数(e){
//单击后关闭除右键之外的所有选项请使用$(文档)添加HTML代码尝试。打开(事件、选择器、函数)以绑定和解除绑定单击handler@JBDouble05:jshiddle addedmeans当选择第二个值时,您只需要打开第三个手风琴?是..请不要使用$(“#容器h3”)。在('click',函数(e){..再次单击事件..我们可以使用$(#container h3').on('click');而不是。。