使用JQuery在XHR响应中单击

时间:2019-02-17 09:11:30

标签: php jquery

我有一个从AJAX加载的表格。在此表单上,有一个我要像这样管理的输入类型按钮

$("#button_id").on("click",function(){..}); 

但这是行不通的...

我的问题是如何进行这项工作?

JavaScript / Jquery加载表单代码

function openForm('commandForm')
{
    $.ajax({
        type: "POST",
        url: "./forms/commandForm.php",
        data: $('#'+frm).
        dataType: "html",
        beforeSend: function(msg){
            $('#ResponseDiv').html('Loding....');
        },
        success: function(back_data){
            $('#ResponseDiv').html(back_data);
        }
    });
}

commandForm.php

<form id="commandForm" action="postCommand.php" method="post" >
    .....
    ....
    <button type="Button" id="postButton" />

</form>

关于postButton onclick的jQuery

$(document).ready(function () {
    $('#postButton').on("click", function (e) {
        /*....*/
    });  //This don't work
}

PS:我不想直接提交表单!只要让我自己的checkform在我的javascript函数中运行...就在这里。因此,我只希望按钮对Onclick做出反应...以便发出警报或其他任何Javacript函数

3 个答案:

答案 0 :(得分:1)

解决了我的jquery事件延迟问题

更多信息在这里。

Event binding on dynamically created elements?

答案 1 :(得分:0)

现在我明白了。 这对您有帮助-

$(document).ready(function () {
$("#id").click(function (e) {
//.........
});  //This will work
}

答案 2 :(得分:-1)

您的表单未提交,因为您未使用提交按钮。 更改按钮元素的类型以从按钮提交,就像这样-

<input type='submit' name='submit' />