【发布时间】:2014-07-28 13:36:36
【问题描述】:
http://protected-river-1861.herokuapp.com/ 链接到我的网站
所以,我需要在按下“输入”键时启动 Google 图片搜索。目前,它仅适用于单击按钮。
HTML:
<p>Enter the keyword to search for images</p>
<input id="search-term" type="text">
<button id="go-search">Go!</button>
<div id="search-results"></div>
<div style="width: 150px; margin:0 auto;">
application.js:
$(document).on('click', '#go-search', function() {
findImagesOnGoogle({
keywords: $('#search-term').val(),
container: '#search-results'
})
});
$(document).on('click', '#search-results img', function() {
var url = $(this).data('url');
$("#workspace img").remove();
var img = $("<img>").attr('src', url);
$("#workspace").append(img);
});
CSS、JS 和 HTML 都在 Sublime Text 中的不同选项卡上。
【问题讨论】:
标签: javascript search input enter