2014-12-28 6 views
0

자바 스크립트 및 htmlalmostfreespeech 호스팅 서비스를 사용하여 친구 용 전자 상거래 웹 사이트를 설정했습니다. html 페이지를 올바르게로드해야하며 오류가 없습니다 (콘솔과 실제 페이지 모두에 있음). 나는 또한 javascript를 html로 임베드하고 2 개의 개별 파일로 시도했지만 어느 것도 작동하지 않습니다. 외부 라이브러리가 없습니다 중 하나를 사용하고 있습니다. 페이지가로드 될 때 알림을 추가했지만 아무것도 표시되지 않았습니다. 페이지 생성자는 onload 이벤트를 통해 body 태그에 설정된 페이지에 연결됩니다. 나는 파이어 폭스, 구글 크롬, 인터넷 익스플로러으로 시도했지만 어느 것도 효과가 없다. 컨트롤의 생성을 html로 옮겼을 때 컨트롤이있었습니다 (의미가 이고 html이입니다). 경고가 표시되지 않았습니다 (자바 스크립트가 생략되거나 onload 이벤트가 해고되지 않음). 여기에 코드입니다 :자바 스크립트가 거의 실행되지 않습니다

<!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> 

답변

3

onload는 함수 이름을지지 않습니다는; 실행할 JavaScript 코드가 필요합니다. 변수를 참조하는 자바 스크립트 코드가 한 줄만있는 경우 :

loadcontrols 

그러면 아무 일도 일어나지 않습니다. 전화를 걸려면 괄호가 필요합니다.

loadcontrols()