[英]php/js/ajax search box
I have a Google style searchbox. 我有一个Google风格的搜索框。 However, unlike with Google I don't want page to change when user selects from suggestions as there are other fields.
但是,与Google不同,我不希望用户从建议中进行选择时更改页面,因为还有其他字段。 Instead, I am using javascript to set a value in the email field once a user selects it.
取而代之的是,一旦用户选择了电子邮件,我就会使用javascript在电子邮件字段中设置一个值。 My problem is all the suggestions remain, filling up screen.
我的问题是所有建议都保留了,填满了屏幕。
javascript: javascript:
function setEmail(address) {
//alert(address);
var email = '<input type="email" name="to" value="\''+address+'\'">';
document.getElementById('box').innerHTML = email;
document.getElementById('suggestions').innerHTML = "";
}
links returned by ajax: ajax返回的链接:
<a href="javascript:void(0);" onclick="setEmail('.$address.');">Name</a>
html: 的HTML:
Edited to show answer below: 编辑以显示以下答案:
<input id="box" type="email" name="to" onkeyup="showSuggestions(this.value)">
Edit 2: To make the suggestions disappear after selection, I set the suggestion box to "". 编辑2:为使建议在选择后消失,我将建议框设置为“”。
You need to give the input an ID. 您需要给输入一个ID。 like this:
像这样:
<input id="emailField" type="email" name="to" onkeyup="showEmail(this.value)">
And change this: 并更改此:
document.getElementById('emailbox').innerHTML = email;
To this: 对此:
document.getElementById('emailField').value = email;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.