日期:2014-05-16  浏览次数:20781 次

新手求解javascript问题
HTML code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>Rob's Rock 'n' Roll Memorabilia</title>
  <link rel="stylesheet" href="css/default.css" />
  <script src="script/thumbanil.js" type="text/javascript"></script>
</head>

<body>
  <div id="wrapper">
    <img src="images/logotypeLeft.png" alt="Rob's Rock 'n' Roll Memorabilia" 
         width="394" height="91" id="logotypeLeft" />
    <img src="images/logotypeRight.png" alt="Rob's Rock 'n' Roll Memorabilia" 
         width="415" height="92" id="logotypeRight" />
    
    <div id="introPane">
      <p>Are you looking for the perfect gift for the rock fan in your life? 
         Maybe you want a guitar with some history behind it, or a conversation 
         piece for your next big shindig. Look no further! Here you'll find all 
         sorts of great memorabilia from the golden age of rock and roll.</p>
      <p><strong>Click on an image to the left for more details.</strong></p>
    </div>
    <div id="thumbanilPane">
      <img src="images/itemGuitar.jpg" width="301" height="105" alt="guitar" 
           title="itemGuitar" id="itemGuitar" />
      <img src="images/itemShades.jpg" alt="sunglasses" width="301" height="88" 
           title="itemShades" id="itemShades" />
      <img src="images/itemCowbell.jpg" alt="cowbell" width="301" height="126" 
           title="itemCowbell" id="itemCowbell" />
      <img src="images/itemHat.jpg" alt="hat" width="300" height="152" 
           title="itemHat" id="itemHat" />
    </div>
    <div id="detailsPane">
      <img src="images/blank-detail.jpg" width="346" height="153" id="itemDetail" />
      <div id="description"></div>
    </div>
  </div>
</body>
</html>


JScript code

window.onload = initPage;

function initPage() {
 
  thumbs = document.getElementById("thumbnailPane").getElementsByTagName("img");

  
  for (var i = 0; i < thumbs.length; i++) {
    image = thumbs[i];
    image.onclick = function() {
      detailURL = 'images/' + this.title + '-detail.jpg';
      document.getElementById("itemDetail").src = detailURL;
      getDetails(this.title);
    }
  }
}


我想单击img标签 就把地址换到itemDetail 我们不好用呢 好像 javascript代码没有加载?

------解决方案--------------------
注意js的引用路径

楼主提供的代码不全,没法测试。
------解决方案--------------------
<div id="thumbanilPane"> 容器id值与JS代码中写得不一样,显然是这里的id值笔误了
thumbs = document.getElementById("thumbnailPane").getElementsByTagName("img");

另外,JS中getDetails()函数未定义,不知道是代码没发全还是确实没有定义。