JQuery 搜索不再工作
我不明白为什么这不起作用。它是一个 JQuery 搜索框,使用 Freebase API 来查找游戏。当我发布时,gameID 和 gameName 为空。
<link type="text/css" rel="stylesheet" href="http://freebaselibs.com/static/suggest/1.3/suggest.min.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="http://freebaselibs.com/static/suggest/1.3/suggest.min.js"></script>
<script type="text/javascript">
$(function() {
$("#game-search").suggest({type:'/games/game'}).bind("fbSelect", function(e, data) {
$("#game-id").val(data.id);
$("#game-name").val(data.name);
});
});
</script>
<form name="input" action="/game-profile" method="post">
<input class="search-box" name="fbSelect" type="text" id="game-search"/>
<input type="hidden" name="gameID" id="game-id" />
<input type="hidden" name="gameName" id="game-name" />
<input class="button" value="Go" type="submit"/>
</form>
I cannot figure out why this isn't working. It's a JQuery search box that uses the Freebase API to find games. When I POST, the gameID and gameName are blank.
<link type="text/css" rel="stylesheet" href="http://freebaselibs.com/static/suggest/1.3/suggest.min.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="http://freebaselibs.com/static/suggest/1.3/suggest.min.js"></script>
<script type="text/javascript">
$(function() {
$("#game-search").suggest({type:'/games/game'}).bind("fbSelect", function(e, data) {
$("#game-id").val(data.id);
$("#game-name").val(data.name);
});
});
</script>
<form name="input" action="/game-profile" method="post">
<input class="search-box" name="fbSelect" type="text" id="game-search"/>
<input type="hidden" name="gameID" id="game-id" />
<input type="hidden" name="gameName" id="game-name" />
<input class="button" value="Go" type="submit"/>
</form>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我抓取了您的代码并将隐藏字段更改为
type="text"
只是这样我可以在从自动完成中进行选择时看到数据。选择时未填充这些字段,因此我快速浏览了 API。看起来您应该绑定的事件是
fb-select
而不是fbSelect
:I grabbed your code and changed the hidden fields to
type="text"
just so I could see the data when a selection was made from the auto-complete. The fields weren't being populated on select, so I took a quick peek at the API.It looks like the event you should be binding to is
fb-select
rather thanfbSelect
a la:它看起来不像您绑定到的 fbSelect 事件,永远不会被触发。您是否包含了使其正常工作所需的所有代码部分?
(通过对原始问题的评论回顾性地回答。@borkweb 更正确。)
It doesn't look like the fbSelect event you're binding to, ever gets fired. Have you included all required code parts for this to work?
(Answered retrospectively via comment on original question. @borkweb is more correct.)