1

我不确定这个最好的标题...

此处提供实时链接

我对这个项目的总体目标。有些文件需要电子邮件才能下载。通过asp.net,我绑定了一个转发器,然后用jquery删除href并将其放在rel标签中,直到他们添加他们的电子邮件地址。

$('a[data-email="True"]').each(function () {
    var href = $(this).attr('href');
    $(this).attr('href', '#_');
    $(this).attr('rel', href);
});

jquery 检查data-email标签是否为“True”,如果是,bootstrap modal则将弹出并通过ajax表单调用 aweb method并将电子邮件添加到数据库中,如果它不是重复的。

$('.emailcheck').live("click", function (e) {        
    if ($(this).data("email") == "True") {
        $('#emailModal').modal();
    }
});

成功后,模式将关闭,并在每个data-email="True"链接上添加回href并将data-email设置为 False

$('#emailModal').modal('hide');
$('body a[data-email="True"]').each(function () {
    var reltag = $(this).attr('rel');
    $(this).attr('href', reltag);
    $(this).attr('data-email', 'False');
});

所有这一切都成功发生,并且电子邮件会在另一次单击时下载。但是,当我单击下载链接时,模式仍然会弹出。

有人可以指导我解决为什么模态仍然弹出的解决方案。另外在成功脚本中有没有办法自动触发下载?

4

1 回答 1

1

试试这个 - 变化不大,但这里有一个jsFiddle显示它应该可以工作

加载函数

$('.emailcheck').each(function() {
    var href = $(this).attr('href');
    $(this).attr('href', '#_').attr('rel', href);
});

点击事件

$(document).on("click", '.emailcheck', function(e) {
    e.preventDefault()
    if ($(this).attr("data-email") == "True") {
        $('#emailModal').modal();
    }
});

邮件提交功能

$('#emailModal').modal('hide');
$('.emailcheck').each(function() {
    var reltag = $(this).attr('rel');
    $(this).attr('href', reltag).attr('data-email', 'False');
});
于 2012-12-21T02:14:46.257 回答