0
我爲朋友建立了一個電子商務網站,使用javascript和html,以及almostfreespeech託管服務。我已經確保正確加載html頁面,並且有沒有錯誤(在控制檯和實際頁面上)。我也嘗試過使用嵌入在html中的JavaScript和2個獨立的文件,但都不起作用。我正在使用也沒有外部庫。我添加了頁面加載時的警報,但沒有顯示出來。頁面構造函數通過在body標籤上設置的onload事件連接到頁面。我用Firefox,谷歌瀏覽器和Internet Explorer進行了試用,但都無效。當我將控件的創建移動到html中時,控件在那裏(意味着html正在工作),但警報仍然沒有顯示(表示JavaScript被忽略或onload事件是不被解僱)。以下是代碼:Javascript not running almostfreespeech
<!DOCTYPE HTML>
<html>
<head>
<title>GetLost</title>
<script type="text/javascript">
function loadcontrols()
{
var items = ["Green cuff", "Red cuff"];
var prices = ["20.00", "30.00"];
var colors = ["Green", "Red"];
var urls = ["http://media-cache-ak0.pinimg.com/736x/0f/f8/11/0ff811addad9b0165263eb73ba9806f0.jpg", "http://www.opalona.com/images/produits/big/big_2049-3.jpg"];
var controls = [];
for(var i = 0; i < items.length; i++)
{
var item = new loaditem(items[i], prices[i], colors[i], urls[i]);
controls.concat(item);
}
alert("All items loaded.")
}
function loaditem(name, value, color, imageUrl)
{
this.name = name;
this.value = value;
this.color = color;
this.imageUrl = imageUrl;
var container = document.CreateElement("div");
container.style.height = "300px";
container.style.width = "200px";
container.style.backgroundColor = color;
scroller.appendChild(container);
var image = document.CreateElement("img");
image.style.height = "220px";
image.style.witdh = "180px";
image.setAttribute("src", imageUrl);
container.appendChild(image);
var name = document.CreateElement("h4");
name.innerHTML = name + " for $" + value;
container.appendChild(name);
alert("The product " + name + "has been loaded.")
}
</script>
</head>
<body onload="loadcontrols">
<h1><b>Choose a product, and click on it to open it.</b></h1>
<div style="overflow-x: scroll" name="scroller" height="310px" width="650px"></div>
</body>
</html>