我有一个选择列表菜单包含产品,并在此菜单上我使用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