gpt4 book ai didi

javascript - jquery如何发布到php,同步

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

我想post到php,当id EmpAgree1时,然后它的post变量EmpAgree=1;当id为EmpAgree2时,则后置变量EmpAgree=2等。但只是读取i的最后一个值,为什么?以及如何解决呢?

谢谢

$(document).ready(function() {
var i;
for(i=1; i <= <?php echo sizeof($id) ?> ; i++) {
$("#EmpAgree"+i).click(function() {
$.post("information_receiving.php", {
EmpAgree : i
});

document.location.href="information_receiving.php";
});
}

最佳答案

您将使用 i 的最后一个值,在本例中为 (sizeof($id))。要解决此问题,请尝试将数字存储在 #EmpAgree 元素中:

$(document).ready(function() {
var i;
for( i=1; i <= <?php echo sizeof($id) ?> ; i++){
$("#EmpAgree"+i).data('nbr', i).click(function(){
$.post("information_receiving.php",{
EmpAgree : $(this).data('nbr')
});
document.location.href="information_receiving.php";
});
}

关于javascript - jquery如何发布到php,同步,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38260148/

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