使用Onchange查找值

时间:2016-02-27 23:00:20

标签: javascript jquery html

我试图创建一个javascript文件,其中包含一个下拉列表,您可以从中选择一个水果,然后抓取所述水果的图像,然后显示价格。我在我的HTML上收到错误,而且我不知道自己可能做错了什么。该脚本没有运行...我编辑了添加了一个javascript下拉列表的开始脚本,因为它是一个私有链接。

HTML:

<script src='* Link of table that provides variable urlBase, array ImageName, & an array containing price'></script>
<br>
<br>
<img id='product image' src='' height='200'>
<br>
<br> PRICE <span id='price display'></span>
<!-- Interface objects go here. -->
<!-- Insert JavaScript here. -->
<script src='js/javascript 10.js'></script>

然后是我的javascript ....

document.getElementById('productID').onchange = function() {
  var productID = this.value;
  productID = parseInt(productID);
  iName = imageName[productID];
  url = urlBase + iName;
  document.getElementById('product image').src = url;
  iPrice = price[productID];
  document.getElementById('price display').innerHTML = iPrice;
};

有什么想法吗?谢谢你的帮助!

这是我收到的错误,我也不明白:

DEBUG TRACE OF OPERATIONS - THESE OPERATIONS WERE ATTEMPTED
1. Check load of home page: javascript 10.html
2. In javascript 10.html:
    Perform: document.getElementById("productID").selectedIndex=0;
    Perform: document.getElementById("productID").selectedIndex=3;
    Perform: document.getElementById('productID').onchange();
    Check: document.getElementById('product image').src;
    Check: document.getElementById('price display').innerHTML;
    Perform: document.getElementById("productID").selectedIndex=1;
    Perform: document.getElementById('productID').onchange();
    Check: document.getElementById('product image').src;
    Check: document.getElementById('price display').innerHTML;
If you do not see your PART 2 grade then your code has an error on javascript 10.html or on the next page after javascript 10.html.

0 个答案:

没有答案