0
我正在尝试使txtHint
每次通过时都是唯一的或不同的。任何帮助创建计数器或增量将非常感激。由于创建唯一的getElement ID
<script type="text/javascript">
function showCustomer(str)
{
var xmlhttp;
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","***.php?q="+str,true);
xmlhttp.send();
}
</script>
http://api.jquery.com/category/ajax/shorthand-methods/,该链接是为你将来的理智。 – mccainz
是否要更改* txtHint *的'ID',还是想在innerHTML中显示发送了什么样的str以及从服务器返回的内容? –
[Math.random()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random) - 会给你一个随机数。如果这是你正在寻找的东西。 – Bakudan