我有这个 jquery 代码:
$("#deletec-box").dialog({
autoOpen: false,
resizable: false,
height:230,
modal: true,
buttons: {
"Confirm": function() {
window.location = 'hrefurlfromclick';
$(this).dialog("close");
},
Cancel: function() {
$(this).dialog("close");
}
}
});
$("#deletec-confirm").click(function() {
$("#deletec-box").dialog("open");
return false;
});
然后在页面中我有一个调用对话框的链接:
<a href="?action=delc&cid=2" id="deletec-confirm">Delete</a>
我的问题是如何获取 href 的值,以便如果用户确认它会加载他们最初单击的链接?
最佳答案
您可以通过以下方式获取 href 属性:$('#deletec-confirm').attr('href');
您的代码现在如下所示:
$("#deletec-box").dialog({
autoOpen: false,
resizable: false,
height:230,
modal: true,
buttons: {
"Confirm": function() {
window.location = $('#deletec-confirm').attr('href');
$(this).dialog("close");
},
Cancel: function() {
$(this).dialog("close");
}
}
});
$("#deletec-confirm").click(function() {
$("#deletec-box").dialog("open");
return false;
});
关于Jquery,从点击中获取url并传递给对话框中的确认按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6575957/