我有一個選擇列表菜單包含產品,並在此菜單上我使用onChangeevent。當您選擇任何產品,它加載product.Below的公司名稱是我使用的功能,jQuery觸發onKeyup事件
function getcompany(element) {
var strURL="getcompany.php?product="+element.value;
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
element.parentNode.parentNode.getElementsByClassName('companydiv')[0].innerHTML=req.responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
而我的HTML代碼,
<select name="product" onChange="getcompany(this)">
<option value="1" >Product1</option>
<option value="2" >Product2</option>
</select>
<div class="companydiv">Product result will be shown here</div>
上面的代碼工作,但現在我想使用jquery自動完成而不是選擇列表菜單因爲我的產品列表包含超過1000個產品。
我的自動完成代碼,但我不知道我錯了
<input name="product" id="product" type="text" onkeyup="getcompany(this)" />
我已經查了一些其他的答案,但我不太滿意的人,他們中的一些下面
jQuery AutoComplete Trigger Change Event
Jquery Autocomplete onChange event
http://forum.jquery.com/topic/autocomplete-and-change-event
什麼問題?函數不被調用?嘗試在自動填充功能中使用「選擇」。 – Hadas 2012-03-26 12:25:44
@哈達斯是的函數不會被調用,我也嘗試按鍵和其他事件,但他們都沒有工作 – Arif 2012-03-26 12:28:58