gpt4 book ai didi

ajax - jQuery 通过类名绑定(bind)表单提交不起作用

转载 作者:行者123 更新时间:2023-12-01 01:28:02 25 4
gpt4 key购买 nike

我有一个 jQuery AJAX 调用,可以在 PHP 中创建并显示这样的表单:

echo '<form class="add_suggested_solution_comment" name="suggest_solution_comment_form" method="post">';
echo '<p><textarea name="suggested_solution_comment" cols=65 rows=6 ></textarea></p>';
echo '<input type="hidden" name="problem_id" value="'.$problem_id.'" />'; echo '<input type="hidden" name="suggestion_id" value="'.$suggested_solution_id.'" />';
echo '<p><input type="submit" class="button" value="Add Comment"></input></p>';
echo '</form>';

然后,当用户单击表单时,我尝试使用表单的 class 属性来捕获 jQuery 中的单击。由于特定原因,我无法使用表单的 id 属性。

这是 jQuery 的样子:

$('.add_suggested_solution_comment').bind('submit',function()

但是由于某种原因,当用户提交表单时,jQuery 永远不会被触发。知道为什么吗?

谢谢!!

最佳答案

如果您通过 AJAX 动态创建 form,则需要使用 jQuery 的 live() 绑定(bind)提交处理程序。方法:

$('.add_suggested_solution_comment').live('submit', function(){
alert('form submitted');
// other code
});

关于ajax - jQuery 通过类名绑定(bind)表单提交不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8013432/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com