PHP/JavaScript的 - 在字符串最后一个字符不会被移除
<form action='' method='post'>
<input type='text' name='username' onkeyup='findUsers(this.value)'>
<input type='submit' value='Add Member'>
<div id='livesearch'></div>
<script>
\t function findUsers(str) {
\t \t if (str == "") {
\t \t \t return;
\t \t } else {
\t \t \t if (window.XMLHttpRequest) {
\t \t \t \t // code for IE7+, Firefox, Chrome, Opera, Safari
\t \t \t \t xmlhttp = new XMLHttpRequest();
\t \t \t } else {
\t \t \t \t // code for IE6, IE5
\t \t \t \t xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
\t \t \t }
\t \t \t xmlhttp.onreadystatechange = function() {
\t \t \t \t if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
\t \t \t \t \t document.getElementById("livesearch").innerHTML = xmlhttp.responseText;
\t \t \t \t }
\t \t \t };
\t \t \t xmlhttp.open("GET","/classes/livemembersearch.php?q="+str,true);
\t \t \t xmlhttp.send();
\t \t }
\t }
</script>
$q = $_GET["q"];
当越来越i的值在findUsers函数中,一切正常,除非当我清空文本字段时,在我清空字段之前它会一直显示最后一个值。
例子:
- 我键入“FFFF”,它更新,我去掉一个F在一个时间,让 更新,直到我删除最近的f,并得到一个空场,它只是 不断显示f通过的值。
- 我输入“hello”,它会更新,当我一次删除整个字符串时, 通过的值保持为hello。
我觉得该函数只是在字段为空时才被调用。
我该如何解决这个问题?在函数中
你能后是应该清空文本框,请功能? – NoobishPro