Tôi đang cố gắng tạo một hộp tìm kiếm nhỏ cho phép bạn tìm kiếm trên Twitter dựa trên từ khóa bạn nhập vào trường nhập. Trong khi nó hoạt động, nó chỉ hoạt động nếu bạn nhấn nút Submit. Tôi cũng muốn có thể nhấn phím Enter hoặc Return để bắt đầu tìm kiếm. Tôi đã thử sử dụng hàm .sumbit và gói đầu vào của tôi xung quanh một phần tử biểu mẫu không thành công. Bất kỳ thông tin chi tiết nào sẽ được đánh giá cao!Chức năng jQuery thực hiện trên nút Bấm và Enter/Return (phím)
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
$(document).ready(function(){
function(data) {
$('#startSearch').click(function(){
$('#tweets .results').remove();
var searchTerm = 'http://search.twitter.com/search.json?q=' + $('#twitterSearch').val() + '&callback=?'
$.getJSON(searchTerm, function(data) {
$.each(data.results, function() {
$('<div class="results"></div>')
.hide()
.append('<a class="userPicLink" href="http://twitter.com/' + this.from_user + '">' + '<img class="userImg" src="' + this.profile_image_url + '">' + '</a>')
.append('<span class="userName">' + '<a href="http://twitter.com/' + this.from_user + '">' + this.from_user + '</span>')
.append('<span class="userText">' + this.text + '</span>')
.append('<time class="textTime">' + relTime(this.created_at) + '</time>')
.appendTo('#tweets')
.fadeIn();
});
});
</script>
<body>
<label id="searchLabel" for="twitterSearch">Search</label>
<input type="search" list="searchSugg" id="twitterSearch" placeholder="css3 animation" required aria-required="true">
<input id="startSearch" type="submit">
<datalist id="searchSugg">
<option value="css3 mulitple backgrounds">
<option value="html5 video">
<option value="responsive web design">
<option value="twitter api">
</datalist>
<div id="tweets">
</div>
</body>
Nếu bạn thực sự sử dụng một
tôi đã thử phương pháp này nhưng tôi đã không thành công. đầu tiên tôi bọc các phần tử HTML trong một '