不理解為什么一直提示聯(lián)系.html:23 Uncaught TypeError: Cannot set property 'onmouseover' of nul ,檢查了好多遍,不懂問題出在那塊兒,哪位大神幫忙看下,謝謝l
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>
dbhs
?? ?</title>
<style type="text/css">
div{
?? ?width:200px;
?? ?height:100px;
?? ?background-color:yellow;
?? ?border:2px solid #000;
?? ?opacity: 0.3;
?? ?filter:alpha(opacity:30);
}
</style>
<script type="text/javascript">
window.onload=function(){
?? ?var odiv =document.getElementById("div");
? odiv.onmouseover=function(){
??? startMove(odiv,'width',400);
? }
}
function startMove(obj,attr,iTarget,fn){
? clearInterval(obj.timer);
? obj.timer=setInterval(function(){
??? var icur=null;
??? if(attr=='opacity'){
????? icur=Math.round(parseFloat(getStyle(obj,attr))*100);
??? }else{
????? icur=parseInt(getStyle(obj,attr));
??? }
??? var speed=(iTarget-icur)/10;
??? speed=speed>0?Math.ceil(speed):Math.floor(speed);
??? if(icur==iTarget){
????? clearInterval(obj.timer);
????? if(fn){
????? fn();
??? }
??? }else{
????? if(attr=='opacity'){
??????? obj.style.filter='alpha(opacity:'+(icur+speed)+')';
??????? obj.style.opacity=(icur+speed)/100;
????? }else{
??????? obj.style[attr]=icur+speed+'px';
????? }
??? }
? },30)
}
function getStyle(obj,attr){
??????? if(obj.currentStyle){
??????????? return obj.currentStyle[attr];
??????? }else{
??????????? return getComputedStyle(obj,false)[attr];
??????? }
??? }
</script>
</script>
</head>
<body>
<div id="div1">
</div>
</body>
</html>
2016-10-18
你的id獲取錯了var odiv =document.getElementById("div");
改成var odiv =document.getElementById("div1");
2016-09-30
我沒有這水平,只能圍觀了
2016-09-23
往上數(shù)倒數(shù)第七行多寫了一個</script>結(jié)束標簽,你看是不是這個原因