亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

關于按鈕提交跳轉不了問題

視頻只教了提示框點擊提交,按鈕提交跳轉不了是出了什么問題

<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>搜索結果1</li>

? ? ? <li>搜索結果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, //當前頁地址。發送請求的地址。

? ? ? ? type: 'get',

? ? ? ? async:true, //默認值: true。默認設置下,所有請求均為異步請求。如果需要發送同步請求,請將此選項設置為 false。

? ? ? ? dataType: 'jsonp',//預期服務器返回的數據類型

? ? ? ? jsonp:'cb',//在一個 jsonp 請求中重寫回調函數的名字

? ? ? ? jsonpCallBack:'callback', ? ? ? ?

? ? ? ? success: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>';

? ? ? ? ? }

? ? ? ? ? $('#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 (){ //在請求出錯時調用

? ? ? ? ? ? console.log("失敗");

? ? ? ? }

? ? ? })

? ?});?

? $(document).bind('click',function(){

? ? ? ?$("#search_suggest").hide();

? });

//提示框點擊提交 ?

$('#search_result').on('click','li',function(){

? ? ?var keyword = $(this).text();

? ? ?location.+keyword;

? })

//按鈕提交 ?

$('#searchButton').on('click',function(){

? ? ?var keytext = $('#search_input').val();

? ? ?location.+keytext;

? })


}) ? ? ?

</script>



正在回答

1 回答

舉報

0/150
提交
取消
搜索框制作
  • 參與學習       66022    人
  • 解答問題       463    個

本課程從簡入深講解搜索框的制作,學習JQ與JS實現Ajax技術的不同點

進入課程

關于按鈕提交跳轉不了問題

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號