第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

Uncaught TypeError: Cannot read property 'style' of null, 是什么情況?

<!DOCTYPE?html>
<html>
<head>
<meta?charset="UTF-8">
<meta?http-equiv="X-UA-Compatible"?content="IE=edge"><!--?為了兼容IE?-->
<title>js實(shí)現(xiàn)搜索框下拉功能</title>
<style?type="text/css">
body,?ul,?li,?div,?form,input{margin:0;?padding:0;}
body{background-color:?#333;}
.bg_div{
background-image:?url(images/river.jpg);?
width:1366px;?height:690px;
margin:0?auto;
position:?relative;
}
.logo{
background-image:?url(images/logo.png);
width:107px;?height:?53px;
float:?left;
margin-right:?15px;
margin-top:?-10px;?/*設(shè)置負(fù)值往反方向移動(dòng)*/
}
form{
float:?left;?
background-color:?#fff;

}
input{
border:?0;?
outline:none;/*去掉chrome下點(diǎn)擊輸入框時(shí)高亮顏色*/
}
.search_input_text{
width:?350px;
height:?38px;
line-height:?38px;
float:?left;
padding:?0?5px;
}
.search_input_button{
background:?url(images/search_button.png)?center?center?no-repeat;
width:?38px;
height:?38px;
line-height:?38px;
float:?left;
cursor:?pointer;?/*光標(biāo)移到按鈕時(shí)變?yōu)椤靶∈帧毙螤?/
}
.search_box{
position:?absolute;
top:?200px;
left:?200px;
}
.suggest?ul{
width:?396px;
border:?1px?solid?#999;
background:?#fff;
position:?absolute;
top:?238px;
left:?322px;
}
.suggest?li{
padding:?3px;
list-style-type:?none;
line-height:?25px;
}
.suggest?li:hover{
text-decoration:?underline;
background-color:?#ccc;
cursor:?pointer;
}
</style>
</head>
<body>
<div>
<div>
<div></div>
<form??id="search_form"?>
<input?type="text"?id="search_input"?/>
<input?type="submit"?value=""?/>
</form>
</div>
<div?id="search_suggest"?style="display:?none;">
<ul?id="search_result">
<li>搜索結(jié)果1</li>
<li>搜索結(jié)果2</li>
<li>搜索結(jié)果3</li>
</ul>
</div>
</div>
<script?type="text/javascript">
//?先封裝幾個(gè)常用的函數(shù)
var?getDOM?=?function?(id)?{
return?document.getElementById('id');
};
var?addEvent?=?function?(id,?event,?fn)?{
var?el?=?getDOM(id)||document;
if(el.addEventListener){//非IE瀏覽器
el.addEventListener(event,?fn,?false);
}else?if(el.attachEvent){//IE瀏覽器
el.attachEvent('on'+event,?fn);
}
};
//?獲取輸入框的位置
var?getElementLeft?=?function(element)?{//獲取距離瀏覽器左邊的距離
var?actualLeft?=?element.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'))+?38?+'px';
getDOM('search_suggest').style.left?=?getElementLeft(getDOM('search_form'))+'px';
getDOM('search_suggest').style.position?=?'absolute';
getDOM('search_suggest').style.display?=?'block';
});
</script>
</body>
</html>

自己看了半天都沒有找出來錯(cuò)誤在哪里啊?

正在回答

3 回答

有沒有完整的代碼資源,可以給一個(gè)鏈接地址嗎?

0 回復(fù) 有任何疑惑可以回復(fù)我~

我居然還看了一會(huì)JS

<div>

<div>

<div></div>

<form??id="search_form"?>

<input?type="text"?id="search_input"?/>

<input?type="submit"?value=""?/>

</form>

</div>

<div?id="search_suggest"?style="display:?none;">

<ul?id="search_result">

<li>搜索結(jié)果1</li>

<li>搜索結(jié)果2</li>

<li>搜索結(jié)果3</li>

</ul>

</div>

</div>

你結(jié)構(gòu)上的class呢?沒寫你就設(shè)置樣式了......

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

慕瓜3177915

啥意思 沒懂
2016-09-21 回復(fù) 有任何疑惑可以回復(fù)我~

自已a(bǔ)lert一下訪問style屬性的那個(gè)元素,那個(gè)元素實(shí)際上取的是空值,可能是你函數(shù)封裝沒封裝好或者獲取的時(shí)候獲取了一個(gè)不存在的元素,代碼太長(zhǎng)就懶得看了OTZ

1 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消
搜索框制作
  • 參與學(xué)習(xí)       66018    人
  • 解答問題       463    個(gè)

本課程從簡(jiǎn)入深講解搜索框的制作,學(xué)習(xí)JQ與JS實(shí)現(xiàn)Ajax技術(shù)的不同點(diǎn)

進(jìn)入課程

Uncaught TypeError: Cannot read property 'style' of null, 是什么情況?

我要回答 關(guān)注問題
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)