關(guān)于按鈕提交跳轉(zhuǎn)不了問(wèn)題
視頻只教了提示框點(diǎn)擊提交,按鈕提交跳轉(zhuǎn)不了是出了什么問(wèn)題
<div class="bg-div"> ?
?<div class="search_box">
?<form action="" method="get" id="search_form"> ? ?
<input type="text" class="search_text" name="q" id="search_input" autocomplete="off" ?value="" />
<input type="submit" class="search_button" id="searchButton" value="" />
</form>?
</div>
</div>
<!-- 提示 -->
<div class="suggest" id="search_suggest" style="display:none;">
? ?<ul id="search_result">
? ? ? <li>搜索結(jié)果1</li>
? ? ? <li>搜索結(jié)果2</li>?
? ?</ul>?
</div>
<script>
?$(function(){
? ? ?$('#search_input').on('keyup',function(){
? ? ? var searchText = $('#search_input').val();
? ? ? $.ajax({
? ? ? ? url: 'http://api.bing.com/qsonhs.aspx?type=cb&q='+searchText, //當(dāng)前頁(yè)地址。發(fā)送請(qǐng)求的地址。
? ? ? ? type: 'get',
? ? ? ? async:true, //默認(rèn)值: true。默認(rèn)設(shè)置下,所有請(qǐng)求均為異步請(qǐng)求。如果需要發(fā)送同步請(qǐng)求,請(qǐng)將此選項(xiàng)設(shè)置為 false。
? ? ? ? dataType: 'jsonp',//預(yù)期服務(wù)器返回的數(shù)據(jù)類型
? ? ? ? jsonp:'cb',//在一個(gè) jsonp 請(qǐng)求中重寫回調(diào)函數(shù)的名字
? ? ? ? jsonpCallBack:'callback', ? ? ? ?
? ? ? ? success:function(d){ //當(dāng)請(qǐng)求之后調(diào)用
? ? ? ? ? var d = d.AS.Results[0].Suggests;
? ? ? ? ? var html = '';
? ? ? ? ? for(var i=0; i<d.length; i++){
? ? ? ? ? ? html+='<li>'+d[i].Txt+'</li>';
? ? ? ? ? }
? ? ? ? ? $('#search_result').html(html);
? ? ? ? ? ? $("#search_suggest").show().css({
? ? ? ? ? ? ? ? top:$("#search_form").offset().top+$("#search_form").height()+10,
? ? ? ? ? ? ? ? left:$("#search_form").offset().left,
? ? ? ? ? ? ? ? position:"absolute"
? ? ? ? ? ? });
? ? ? ? ?},
? ? ? ? ?error:function (){ //在請(qǐng)求出錯(cuò)時(shí)調(diào)用
? ? ? ? ? ? console.log("失敗");
? ? ? ? }
? ? ? })
? ?});?
? $(document).bind('click',function(){
? ? ? ?$("#search_suggest").hide();
? });
//提示框點(diǎn)擊提交 ?
$('#search_result').on('click','li',function(){
? ? ?var keyword = $(this).text();
? ? ?location.+keyword;
? })
//按鈕提交 ?
$('#searchButton').on('click',function(){
? ? ?var keytext = $('#search_input').val();
? ? ?location.+keytext;
? })
}) ? ? ?
</script>
2022-03-26
謝謝親的支持,后面會(huì)推出更優(yōu)秀的課程。$.getJSON("Data/sport.json",function(data){...});data是通過(guò)上述方式返回來(lái)的json格式的數(shù)據(jù).index是遍歷時(shí)各項(xiàng)元素的索引號(hào),自動(dòng)獲取。