如何在执行搜索后根据结果创建搜索历史并能够在 searchHistory div 中显示?基本上显示并存储输入到搜索栏中的所有搜索值?
<html>
<head>
<title>Twitter Search</title>
<script src="https://code.jquery.com/jquery-1.10.1.min.js"></script>
</head>
<body>
<h1>Twitter Search</h1>
<div><label for="search">Search twitter: </label>
<input type="text" name="search" id="search" /></div>
<div><input type="button" id="btnSearch" value="Search"></div>
<div>
<ul id="resultList">
</ul>
</div>
<div>
<ul id = "searchHistory">
</ul>
</div>
<script type="text/javascript">
$(document).ready(function () {
$("#btnSearch").click(function () {
$("#resultList").empty();
$.ajax({
data: {
q: $("#search").val(),
count: 10
},
url: 'twitter.php/search/tweets.json?q=my%20search&count=10',
type: 'GET',
dataType: 'json',
success: function (serverResponse) {
for (var i = 0; i < serverResponse.statuses.length; i++) {
var tweet = serverResponse.statuses[i];
$("#resultList").append("<li>" + tweet.text + "</li>");
}
}
});
});
});
</script>
</body>
</html>