2016-05-09 109 views
1

我有一个div,它每3秒刷新一次。在div里面有一个输入框,我输入的任何内容都会在3秒内被清除。有没有办法让文本留在输入框中,而不是清除掉?在输入框内的div刷新文本不应该清除

index.js

<div id="show_here"></div> 
<script type ="text/javascript"> 
    $(document).ready(function() { 
     setInterval(function() { 
      $('#show_here').load('fetch.php') 
     }, 3000); 
    }); 
</script> 

fetch.php

<div> 
    // some code here 
    <input type="text" id="input" /> 
</div> 

输入框需要是页面内,因为它是一个while循环中。这可以做到或者我需要改变我的整个代码,使这项工作?

+0

请好一点的格式化你的问题;真的很难理解你想说什么,并且你的代码看起来真的很狡猾......为了回答你的问题,为什么不删除让你的div每3秒刷新一次的代码? :) – webeno

+0

你为什么每3秒加载'fetch.php',我没有看到有什么更新 –

+0

你进入文本框?如果是这样,你为什么每3秒刷新一次? –

回答

2

保留,然后设置

setInterval(function() { 
    my_val = $('#input').val(); 
    $('#show_here').load('fetch.php'); 
    $('#input').val(my_val); 
}, 3000); 
+0

它不起作用输入框仍然刷新 – james2569

+0

#show_here什么是/哪里是?显示相关代码.. #show_here和#input之间存在哪种关系? – scaisEdge

+0

div'input'不在索引页面里面'fetch.php'中 where'show_here'在'index.php'里面 – james2569