开发者

JQuery bind function to multiple objects

How can we edit the code below to bind this function to both myLink and myButton.

if (section === x) {
    myButton = $("#a");
    myLink = $("#b");
} else {
    myButton = $("#c")开发者_高级运维;
    myLink = $("#d");
}

myLink.click(function(e) { 
    e.preventDefault();
    showMyDialog();
});


if (section === x) {
    $("#a,#b").click(OnClick);
} else {
    $("#c,#d").click(OnClick);
}

function OnClick(e) { 
    e.preventDefault();
    showMyDialog();
});


if (section === x) {
    $("#a,#b").addClass('clickable');
} else {
    $("#c,#d").addClass('clickable');
}


$('.clickable').click(function(e) { 
    e.preventDefault();
    showMyDialog();
});


if (section === x) {
    myButton = $("#a, #b");
} else {
    myButton = $("#c, #d");
}

myButton.click(function(e) { 
    e.preventDefault();
    showMyDialog();
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜