gpt4 book ai didi

javascript - 我的 onclick 成功进行了 ajax 调用,但由于某种原因没有执行alert(1);

转载 作者:行者123 更新时间:2023-12-01 03:11:50 24 4
gpt4 key购买 nike

所以我的 ajax 调用成功执行并更新了我的数据库,但是,我包含的其他任何内容都不起作用。此警报(1);不发出任何警报。里面的任何点击事件句柄都不起作用,我不知道为什么。

html

echo    "<div class='upvoteDownvoteRatingContainer'>
<form class='upvoteImage' method='POST' action=''>
<input type='hidden' name='action' value='upvote'>
<input type='hidden' name='id' value='".$row['id']."'>
<input type='hidden' name='userId' value='".$currentUser."'>
<button class='upvoteImageButton' type='submit'><img class='arrowUp' src='../images/Social Media/arrowUp.png' alt='submit'></button>";
echo "</form>";

Javascript

$('.arrowUp').onclick(function(e){
e.preventDefault();
alert(1);
var form = $(this);

var id = form.find("input[name='id']");
var userId = form.find("input[name='userId']");
var action = form.find("input[name='action']");
var ratingNumber = form.parent('.upvoteDownvoteRatingContainer').find('.ratingNumber');

$.post('../includes/voting.inc.php', {id: id.val(), userId: userId.val(), action: action.val()}, function(data){
ratingNumber.html((data));
}, 'json');
});

最佳答案

在 jQuery 中,.onclick() 函数不存在。您可以执行以下操作:

$('.arrowUp').on('click', function(){ /* ... */ });

或者这个:

$('.arrowUp').click(function(){ /* ... */ });

关于javascript - 我的 onclick 成功进行了 ajax 调用,但由于某种原因没有执行alert(1);,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45775682/

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