简体   繁体   English

我无法获得输入框的值

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

I'm trying to build an script that when the user scrolldown, it shows more results. 我正在尝试构建一个脚本,当用户向下滚动时,它将显示更多结果。

I inserted into an array with some values, and i inserted an if statement, that counts the number of values that are permited per page. 我插入了具有一些值的数组,并插入了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;


    }

?> ?>

I created an hidden input, it has the 1 value. 我创建了一个隐藏的输入,它的值为1。

I did that because i want to change the value using JQuery 我这样做是因为我想使用JQuery更改值

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

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

        }
    });
</script>

All code 所有代码

    <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>

Input 输入项

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

But it can't recognize the input hidden. 但是它无法识别隐藏的输入。

Your code doesnt have any hidden input type. 您的代码没有任何hidden输入类型。 Hidden input should be like, 隐藏的输入应该像

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

Then for incrementing, 然后增加

 $(window).scroll(function () {

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

     }
 });

You should use parseInt() because val() will return string type. 您应该使用parseInt()因为val()将返回字符串类型。

Before looking at anything at all, the very first thing I would suggest is to look at what the page is loading into iteelf with the post values etc. 在完全查看任何内容之前,我建议的第一件事是使用post值等查看页面正在加载到iteelf中的内容。

The very simplest way to do this is to use a web traffic debugger tool. 最简单的方法是使用网络流量调试器工具。 The one I use for this is Fiddler2, there are many like this, this one is mine (recommendation). 我为此使用的是Fiddler2,有很多这样的,这是我的(推荐)。

It will mean that you don't need to write any code to look at what the page think's it's doing, you can SEE it from the actual traffic that is that page's request/response instance. 这意味着您无需编写任何代码即可查看该页面在做什么,您可以从该页面的请求/响应实例的实际流量中看到它。

Then if you have something in POST values, is it actually what you expect? 然后,如果您在POST值中有内容,那实际上是您所期望的吗? If it is then it's the code that looks at that value, otherwise its the code that generates it.. 如果是,那么代码就是查看该值的对象,否则就是生成该值的代码。

Hope that helps :) 希望有帮助:)

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

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