jquery:自动完成返回名称和 ID?
实际上我有这个html界面;
<input type="text" size="20" name="brandname" />
<input type="hidden" name="brandid" value="" />
实际上上面有一个隐藏的输入值,即“brandid”。
下面是jquery;
$('#brandname').autocomplete("searchbrandnames.jsp", {
minChars: 3
});
好吧……这里的想法是; 一旦用户在该文本字段中输入内容, jquery 将具有某种自动完成功能...就像 google 所做的那样。
但是在这里,如果我们从上面的界面注意到, 那里有一个隐藏的价值,绿色。
该隐藏值将用作存储的隐藏变量。 那一个,让我对这个话题产生了疑问。
获得自动完成到文本字段以及将id放入隐藏值的最佳方法是什么? 在上面的例子中;假设
- 我们在文本字段中输入一个品牌名称,
- 然后 jquery 向数据库请求一些类似的品牌名称,
- 它返回了它们的名称及其 id;分别为文本字段 1 和隐藏值 1。
但是,就我现在使用 jquery 而言,有很多可用的插件... 只是将值返回到一个位置,也没有将许多值返回到多个位置。我说的地方是指 html 元素。
嗯……这个案子有结果吗?
Actually I have this html interface;
<input type="text" size="20" name="brandname" />
<input type="hidden" name="brandid" value="" />
Actually above there is a hidden input value namely as "brandid".
And below is the jquery;
$('#brandname').autocomplete("searchbrandnames.jsp", {
minChars: 3
});
OK... the ideas here is that;
Once the user type something into that textfield,
the jquery will work to have a somekind of autocomplete... like what google does for example.
But here, if we notice from the interface above,
There is a hidden value there, Green colored.
That hidden value is going to be used as a hidden variable stored.
That one, that made me question this thread.
What is the best way to obtain autocomplete into the textfield and also by getting the id into the hidden value as well?
In above example; let's assume,
- we are typing a brand name into the textfield,
- then jquery request into the db for some similar brand names,
- it returned their names with their id; respectively 1 to the textfield and another 1 into the hidden value.
But, as far as I'm working with jquery right now, many plugins available there...
just returned values into a single place nor many values into many places. I'm saying places means, referring to the html elements.
Hmmm.... is there any turn out for this case?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您使用 jQuery UI 中的自动完成功能,
value
和id
项属性将根据 JSP 文件返回的数据而有所不同。请参阅http://jqueryui.com/demos/autocomplete/#custom-data
Assuming you're using the Autocomplete from jQuery UI
The
value
andid
item properties will differ depending on the data returned by your JSP file.See http://jqueryui.com/demos/autocomplete/#custom-data