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

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

請問出了什么問題?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>bing search</title>

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

<style type="text/css">

body{background-color:#333;}

.bg-div{position:relative; background-image:url(river.jpg);width:1665px; height:900px; margin:0 auto;}

.logo{margin:-6px 18px 0 0; background-image:url(logo.png);width:107px; height:53px; float:left;}

form{float:left; background-color:#fff; padding:1px; height:30px;}

.search-input-text{border:0; float:left; width:330px; height:29px; line-height:29px; outline:none;}

.search-input-button{border:0;width:29px; height:29px; background-image:url(search-button.png); float:left;}

.search-box{

position: absolute;

top: 401px;

left: 604px;

}

.suggest{width:330px; background-color:#fff; border:1px solid #999;}

.suggest ul{list-style:none; margin:0; padding:0;}

.suggest ul li{padding:3px; font-size:14px; line-height:25px; cursor:pointer;}

.suggest ul li:hover{text-decoration:underline; background-color:#e5e5e5;}

</style>

</head>


<body>

<div class="bg-div">

? ? <div class="search-box">

? ? <div class="logo"></div>

? ? ? ? <form class="search-form" action="https://cn.bing.com/search" target="_blank" id="search-form">

? ? ? ? <input type="text" class="search-input-text" ?name="q" id="search_input" autocomplete="off"/>

? ? ? ? ? ? <input type="submit" class="search-input-button" value=""/>

? ? ? ? </form>

? ? ? ? ? </div>

? ? </div>

? ?<div class="suggest" id="search-suggest" style="display:none">

? ? <ul id="search-result">

? ? ? ? <li>搜索結果1</li>

? ? ? ? ? ? <li>搜索結果2</li>

? ? ? ? ? ? <li>搜索結果3</li>

? ? ? ? </ul>

? ?

? ?</div>

? ?

<script>

var getDOM=function(id){

return document.getElementById(id);

}

var addEvent=function(id,event,fn){

var el=getDOM(id)||document;

if(el.addEventListener){

el.addEventListener(event,fn,false);

}

else if(el.attachEvent){

el.attachEvent('on'+event,fn);

}

}

var getElementLeft=function(element){

var actualLeft=element.offsetLeft;//offsetLeft是獲得距離父元素左邊的距離

var current=element.offsetParent;

while(current!=null){

actualLeft+=current.offsetLeft;

current=current.offsetParent;

}

return actualLeft;

}

var getElementTop=function(element){

var actualTop=element.offsetTop;

var current=element.offsetParent;

while(current!==null){

actualTop+=current.offsetTop;

current=current.offsetParent;

}

return actualTop;

}

addEvent('search_input','keyup',function(){

getDOM('search-suggest').style.top=getElementTop(getDOM('search-form'))+29+'px';

getDOM('search-suggest').style.left=getElementTop(getDOM('search-form'))+'px';

getDOM('search-suggest').style.position='absolute';

getDOM('search-suggest').style.display='block';

})

</script>

</body>

</html>

情況如圖:http://img1.sycdn.imooc.com//5843505800019e1a09680389.jpg

提示框怎么變化到那里去了?


正在回答

1 回答

樓主馬虎了

getDOM('search-suggest').style.left=getElementTop(getDOM('search-form'))+'px';里應該是Left,不是Top

0 回復 有任何疑惑可以回復我~
#1

慕粉3988711 提問者

非常感謝!這種小錯誤不該犯的
2016-12-05 回復 有任何疑惑可以回復我~

舉報

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

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

進入課程

請問出了什么問題?

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

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

幫助反饋 APP下載

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

公眾號

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