当我单击按钮时,未定义功能



i使用函数function makeModalEnroll(name, description, i, id)生成模态表单在我的一条线中,有一个字符串

modal += '<button type="button" id="enroll' + i + '" class="btn btn-success" data-dismiss="modal" onclick="send(this.id);"> Enroll <span class="glyphicon glyphicon-arrow-right"></span> </button>';

我有函数send,现在我用id = 0

提交表单
function send(id) {
    alert(id);
    var c = id.charAt(id.length - 1);
    alert(c);
    $('#enrollForm0').ajaxSubmit({url: 'enroll.html', type: 'post'});
};

但是浏览器说ReferenceError: send is not defined。我试图在函数makeModalEnroll之前和之后放置函数send,但总是发生此错误。

如何解决此问题?

可能是您不将功能公开到全局范围,请尝试以下操作:

window.send = function(id) {
    alert(id);
    var c = id.charAt(id.length - 1);
    alert(c);
    $('#enrollForm0').ajaxSubmit({url: 'enroll.html', type: 'post'});
};

最新更新