[英]uncaught type error when constructing new object
我正在拼湊一些腳本來在我的頁面上創建浮雲。
使用腳本使用的完整說明(可以在本文的底部找到)我創建了一個函數,它生成一個圖像元素,將它附加到div,將div附加到頁面並調用“芯片”構造函數。 我在for循環中調用函數來獲取頁面上我想要的雲數。
這是for循環:
for ( var i = 0; i <= cloudNo/4; i ++ ) {
// call a function which creates a new div and chip object
var cloudName = "flyingCloud" + i.toString();
newCloud(i);
movechip(cloudName);
}
這是功能:
// cloud function
function newCloud(number) {
// assign a 'name' to the cloud to be used as the id and then passed to the chip function
var cloudName = "flyingCloud" + number.toString();
// create a div element to house the image
var cloud = document.createElement('div');
// create an image element
var cloudImg = document.createElement('img');
// append the image to the div
cloud.appendChild(cloudImg);
// assign image src as cloud url
cloudImg.src = cloudImageUrl;
// assign the cloudname as the ID
cloud.id = cloudName;
// set the style of the cloud div
cloud.setAttribute('style', 'position:absolute; left: -500px; width:50; height:62; font-size:10px;');
// append the cloud to the container div
cloudDiv.appendChild(cloud);
// create a new chip
cloud = new Chip(cloudName, 362,362);
}
但我一直收到這個錯誤:moveobj.js:71 Uncaught TypeError:無法讀取屬性'style'的null(...)
這里是問題代碼的鏈接,第71行試圖訪問'chip'的樣式屬性: http : //samisite.com/extras/HTMLobj-1640/moveobj.js
我意識到這可能是一個非常容易解決的問題,但似乎無法弄清楚什么是錯的。 任何意見我都會非常感激。
完整的說明可以在這里找到: http : //dynamicdrive.com/dynamicindex4/flyimage.htm
setAttribute只覆蓋style屬性到最后一個! 我不知道,所以我找到了另一個解決方案
cloud.style.position = "absolute";
cloud.style.left = "-500px";
cloud.style.width = "50px";
cloud.style.height = "62px";
cloud.style.fontSize = "10px";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.