大神幫忙解釋下
<body>
<div id="bg">
? ?<div id="search">
? ?<div id="logo"></div>
? ?<form class="search-form" id="search-form" action="http://www.biying.com">
? ? ? ?<input type="text" class="search-text" id="search-input">
? ? ? ?<input type="button" class="search-button">
? ?</form>
? ?</div>
? ?<div class="suggest" id="suggest">
? ? ? ?<ul id="search-result">
? ? ? ? ? ?<li>搜索內(nèi)容1</li>
? ? ? ? ? ?<li>搜索內(nèi)容2</li>
? ? ? ? ? ?<li>搜索內(nèi)容3</li>
? ? ? ? ? ?<li>搜索內(nèi)容4</li>
? ? ? ?</ul>
? ?</div>
</div>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script>
? ?$(document).ready(function(){
? ? ? ? ? ?$("#search-input").bind('keyup',function(){
? ? ? ? ? ? ? ?var searchText = $('#search-input').val();
? ? ? ? ? ? ? ?$.get('http://api.bing.com/qsonhs.aspx?q='+searchText,function(d){
? ? ? ? ? ? ? ? ? ?var d = d.AS.Results[0].Suggests;
? ? ? ? ? ? ? ? ? ?var html='';
? ? ? ? ? ? ? ? ? ?for(var i=0;i<d.length;i++) {
? ? ? ? ? ? ? ? ? ? ? ?html += '<li>' + d[i].Txt + '</li>';
? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ? ? ?$("suggest").html(html);
? ? ? ? ? ? ? ? ? ?$("#suggest").show().css({
? ? ? ? ? ? ? ? ? ? ? ?position:"absolute",
? ? ? ? ? ? ? ? ? ? ? ?top:$("#search-form").offset().top+$("#search-form").height()+10,
? ? ? ? ? ? ? ? ? ? ? ?left:$("#search-form").offset().left
? ? ? ? ? ? ? ?});
? ? ? ?},"json")
? ? ? ?});
? ?});
</script>
</body>
2016-09-24
你已經(jīng)在腳本里面動態(tài)加載li元素了,就不用在html文檔內(nèi)寫li標簽了。