0

我有以下代码现在效果很好,

<!DOCTYPE html>
<html>
<body> 
    <div id="one">
    echo "data 1";
   <input type="hidden" id="one" name ="one" value="'.$one.'">

  </div>

  <div id="two">
     echo "data 1";
    <input type="hidden" id="two" name="two" value="'.$one.'">

  </div>
</body> 
</html>

对于每个 DIV,我有数据 1 2 3...更多来自 MySQL php 查询。因此,当 Hidden Id = one 延迟几秒钟并显示下一个结果数据 2 时,直到我们再次将输入隐藏到一个。这一切都来自数据库。自动地。我有所有的工作。

我可以使用 ajax 来显示数据,但是当我来读取输入值并进行相应更改时。我有问题...

我努力了..

var value1  = $('one').attr( "value" ); //
 var value2  = $('two').attr( "value" ); //
 (function data() {
                $.ajax({
                    url: 'data.php',
                    if (value1 == 'one') { 
                    success: function(data) {
                    $('#one').html(data);
                    },
                    }
                    complete: function() {
                        // Schedule the next request when the current one's complete
                        setTimeout(data, 5000);
                    }
                });
            })();

但它似乎不起作用......

4

1 回答 1

1

一些小的修改可能有助于这项工作:

<!DOCTYPE html>
<html>
<body> 
    <div id="div-one">
    <?php echo "data 1"; ?>;
   <input type="hidden" id="one" name ="one" value="<?php $one; ?>;">

  </div>

  <div id="div-two">
     <?php echo "data 2"; ?>;
    <input type="hidden" id="two" name="two" value="<?php $two; ?>;">

  </div>
</body> 
</html>

Javascript:

var value1  = $('#one').val();
var value2  = $('#two').val();
 (function data() {
                $.ajax({
                    url: 'data.php',
                    success: function(data) {
                       if (value1 == 'one') { 
                          $('#div-one').html(data);
                       }
                    },
                    complete: function() {
                        // Schedule the next request when the current one's complete
                        setTimeout(data, 5000);
                    }
                });
            })();
于 2013-10-17T10:11:43.330 回答