0

我创建了一个变量targetForm并尝试将其与submit(). 但是,当我调用函数并触发变量来提交表单时,绑定函数不会捕获提交事件。

var targetForm;

function Add_Notice_Message(evt){

    alert('set up form');

    targetForm = document.notification_form;
    targetForm.classname= 'TTWForm';
    targetForm.method = "post";
    targetForm.action = '';
    targetForm.novalidate = '';

    alert('beforesubmmit'); 
    targetForm.submit();
}

$( targetForm ).bind(
    "submit",
    function( event ){
        alert('submit');

        var $form = $(this), type;
        type = $form.find('#type').val();

        var options = {
            category:'projects',
            message: 'Sample Notification'
        };

        notifications.createNotification(options);
        return false;
    }
);
4

1 回答 1

1

您在变量获取值之前绑定了它。

您应该设置一次变量(可能在 Add_Notice... 函数之外),然后绑定它。

于 2013-01-01T10:14:25.217 回答