jQuery 将点击选择器传递到 IF 语句中
我正在尝试创建一个 jQuery 函数来检查是否在 Facebox 对话框上按下了“取消”或“删除”按钮,但是我不太确定如何进行操作。
现在,我有:
// Confirm and remove group members
$("[id^='removeGroupMember_']").click(function () {
confirmDialog('Removal', 'Are you sure you want to remove this person from the group?');
// I need to check the results of the confirm dialog prior
// to calling the code below to remove the actual rows
$(this).parent().slideUp("fast", function () {
$(this).remove();
updateGroupRows();
});
return false;
});
其中 confirmDialog
是:
function confirmDialog(action, message) {
$.facebox('<h3 class="confirmHeader light tb">Confirm ' + action + '</h3><div class="confirmContent"><p>' + message + '</p><a href="#" id="dialogConfirmAction" class="ras small red button right">' + action + '</a><a href="#" id="dialogConfirmCancel" class="ras small gray button right">Cancel</a></div>');
};
现在,我有两个函数用于按下这些按钮,但我不知道如何检查它们的结果并将其反馈回来,以便我可以决定是否删除关联行:
$('#dialogConfirmAction').live('click', function() {
console.log('Yep... they dun clicked it.');
return true;
});
$('#dialogConfirmCancel').live('click', function() {
$.facebox.close();
return true;
});
非常感谢您提供的任何指导!
I am trying to create a jQuery function to check whether a Cancel or Remove button was pressed on a facebox dialog, however I am not quite sure how to go about it.
Right now, I have:
// Confirm and remove group members
$("[id^='removeGroupMember_']").click(function () {
confirmDialog('Removal', 'Are you sure you want to remove this person from the group?');
// I need to check the results of the confirm dialog prior
// to calling the code below to remove the actual rows
$(this).parent().slideUp("fast", function () {
$(this).remove();
updateGroupRows();
});
return false;
});
Where confirmDialog
is:
function confirmDialog(action, message) {
$.facebox('<h3 class="confirmHeader light tb">Confirm ' + action + '</h3><div class="confirmContent"><p>' + message + '</p><a href="#" id="dialogConfirmAction" class="ras small red button right">' + action + '</a><a href="#" id="dialogConfirmCancel" class="ras small gray button right">Cancel</a></div>');
};
Right now, I have two functions for when those buttons are pressed, but I'm not sure how to check their result and feed that back in so I can decide whether or not to delete the associated row:
$('#dialogConfirmAction').live('click', function() {
console.log('Yep... they dun clicked it.');
return true;
});
$('#dialogConfirmCancel').live('click', function() {
$.facebox.close();
return true;
});
Any guidance you can provide is greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您想要做的是将您的
confirmDialog
函数更改为如下所示:然后,您可以通过将函数传递给
confirmDialog
函数来传递您想要“执行操作”时发生的情况。这将使您的其他代码如下所示:您可以通过添加另一个变量来扩展它,以说明取消时要执行的操作。
What you want to do is change your
confirmDialog
function to be like so:You can then pass what you want to happen "on action" by passing a function to the
confirmDialog
function. This would make your other code look like this:And you can extend that by adding another variable to say what to do on cancel.
试试这个:
Try this: