gpt4 book ai didi

jquery - jQuery 帖子上没有发生任何事情

转载 作者:行者123 更新时间:2023-11-28 14:11:31 25 4
gpt4 key购买 nike

下面是我的 jQuery 函数,用于将名称、密码和电子邮件的值发布到 register.php,然后显示在 register.php 中回显的消息div#message.

但是,当我点击 postBtn 时,没有任何反应,控制台也没有记录点击。

jQuery

$(document).ready(function() {
$("#btnPost").on("click", function() {
console.log('clicked');
var thisBtn = $(this);
var parent = thisBtn.parent();

name = parent.data('name');
password = parent.data('password');
email = parent.data('email');

$.post(
'register.php',
{
name: ('name'),
password: ('password'),
email: ('email')
},
function(data) {
parent.next('#message').html(data);
}
);
});
});

这是输入所有数据的 HTML block ,但是单击 #postBtn 按钮时似乎没有任何反应。

<table>
<tr>
<td> Username: <td>
<td> <input type = "text" class = "field" name = "name"> </td>
</tr>
<tr>
<td> Password: <td>
<td> <input type = "password" class = "field" name = "password"> </td>
</tr>
<td > Email: <td>
<td> <input type = "email" class = "field" name = "email"> </td>
</tr>
<tr>
<td> <td>
<td> <button class='regular' id = "btnPost" name='save'> Log In </button></td>
</tr>
<tr>
</table>

最佳答案

我使用相同的语法遇到了与您类似的问题,我按照以下几行重新处理了我的问题,它解决了这个问题....

尝试:

$(document).on("click", "#btnPost", function() { //implementation });

您可以将 $(document) 更改为包含 div 的名称,或较低级别的名称,只要 #btnPost 包含在其中即可。

关于jquery - jQuery 帖子上没有发生任何事情,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9417079/

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