我正在嘗試使用ajax進行自動完成搜索。我希望不需要使用不同顏色(黑色)的字符。自動完成:以不同顏色顯示未完成的字符
<script>
function showResult(str) {
if (str.length==0) {
document.getElementById("livesearch").innerHTML="";
document.getElementById("livesearch").style.border="0px";
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 (this.readyState==4 && this.status==200) {
document.getElementById("livesearch").innerHTML=this.responseText;
document.getElementById("livesearch").style.border="1px solid #A5bCB2";
}
}
xmlhttp.open("GET","livesearch.php?q="+str,true);
xmlhttp.send();
}
</script>
<body>
<form>
<input type="text" size="30" onkeyup="showResult(this.value)">
<div id="livesearch"></div>
</form>
</body>
我livesearch.php樣子:
echo "Tirana";
echo "Tepelene";
echo "Korca";
echo "Skrapar";
對於exhample:(照片)
能否請你幫我! 在此先感謝!
嘗試'$( 'UI的自動完成' ).css('color','red');'顏色爲紅色 – KingRider