繁体   English   中英

我无法获得输入框的值

[英]I can't get the input box value

我正在尝试构建一个脚本,当用户向下滚动时,它将显示更多结果。

我插入了具有一些值的数组,并插入了if语句,该语句计算每页允许的值数量。

<?php
    $arr = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20);
        $i = 0;

        $more = 1;
        foreach ($arr as $value) {

        echo $value;
        echo '<br>';
          if(++$i > $more*9) break;


    }

?>

我创建了一个隐藏的输入,它的值为1。

我这样做是因为我想使用JQuery更改值

<script>
    $(window).scroll(function () {

        if ($(document).height() <= $(window).scrollTop() + $(window).height()) {
        //insert +1 to the hidden input value

        }
    });
</script>

所有代码

    <style>
    div{ height: 1000px}
    </style>
<div>
<form method="POST">
<input type="text" value="1" name="more" />
</form>
  <?php
$arr = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20);
    $i = 0;

    $more = $_POST['more'];
    foreach ($arr as $value) {

    echo $value;
    echo '<br>';
      if(++$i > $more*9) break;


}

  ?>
</div>

    <script>
    $(window).scroll(function () {

        if ($(document).height() <= $(window).scrollTop() + $(window).height()) {
        alert('<?= $more ?>');

        }
    });
</script>

输入项

  <form method="POST">
<input type="hidden" value="1" name="more" />
</form>

但是它无法识别隐藏的输入。

您的代码没有任何hidden输入类型。 隐藏的输入应该像

<input type="hidden" value="1" />

然后增加

 $(window).scroll(function () {

     if ($(document).height() <= $(window).scrollTop() + $(window).height()) {
         $("input[type='hidden']").val(parseInt($("input[type='hidden']").val()) + 1);

     }
 });

您应该使用parseInt()因为val()将返回字符串类型。

在完全查看任何内容之前,我建议的第一件事是使用post值等查看页面正在加载到iteelf中的内容。

最简单的方法是使用网络流量调试器工具。 我为此使用的是Fiddler2,有很多这样的,这是我的(推荐)。

这意味着您无需编写任何代码即可查看该页面在做什么,您可以从该页面的请求/响应实例的实际流量中看到它。

然后,如果您在POST值中有内容,那实际上是您所期望的吗? 如果是,那么代码就是查看该值的对象,否则就是生成该值的代码。

希望有帮助:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM