SweetAlert不允许用户进行交互

时间:2014-10-16 18:57:11

标签: jquery sweetalert

我正在使用SweetAlert.js来替换典型的alert();函数。点火订单存在问题,在用户尝试提交不完整的表单后我无法保留。在"显示" jsFiddle上的模式,警报在页面加载时触发。在我设置的实际页面中,它根本没有触发,但警报的文本显示在页面底部。

jsFiddle:http://jsfiddle.net/mattography/d8s7rm19/1/

$("#submit").click(function () {
if ('localStorage' in window && window['localStorage'] !== null) {
    try {
        //Get stored data
        var users = JSON.parse(localStorage.getItem('users'));

        if (users === null) {
            //If no stored data, create empty array
            //users = [];
            sweetAlert("Oops...", "Something went wrong!", "error");
        }

        //Create new user entry
        user = {
            name: $(".name").val(),
            phone: $(".phone").val(),
            website: $(".website").val(),
            contact: $(".contact").val()
        };

        //Add new entry to stored array
        users.push(user);

        //Save array
        localStorage.setItem("users", JSON.stringify(users));

        alert("The data was saved.");
        return true;

    } catch (e) {
        if (e == QUOTA_EXCEEDED_ERR) {
            alert('Quota exceeded!');
        }
    }
    } else {
        alert('Cannot store user preferences as your browser do not support local storage');
    }
});

1 个答案:

答案 0 :(得分:0)

您需要阻止处理链接事件。在这种情况下,请使用:

event.preventDefault()
// and
return false;

请参阅更新的解决方案:http://jsfiddle.net/d8s7rm19/2/