簡體   English   中英

此代碼在IE中均適用於所有其他瀏覽器

[英]This code works in all other browsers except in IE

這在所有瀏覽器中都可以正常工作,但IE誰都可以解釋原因,因此我可以修復它。 我正在根據下拉列表中所選索引的索引顯示javascript對象的索引

 $(document).ready(function () {
var pdata = [{ Name: "Apples", Price: 1.99 },{ Name: "Bananas", Price: 2.45 } ];

    $('#produceTMPL').tmpl(pdata).appendTo('#produceList');

      $(document).ready(function () {


      $('#add1').click(function () {
        var selected = $('#produceList option:selected').index();

        item = pdata[selected];

        console.log(selected);
        $('#cart').append('<p>' + item.Name + ', ' + item.Price + '</p>');




    });  
    });

HTML:

     <div>
  <select id="produceList">
  <option>make a selection</option>
  </select>

item是IE中窗口對象的受保護屬性。 只需重命名您的變量,或在函數中正確聲明它(使用var )。

console.log在IE中引發錯誤,因此為了安全起見,請勿在未檢查瀏覽器是否支持console.log的情況下使用console.log。

try{
    if(console && console.log) console.log('message')   
}catch(e){}

要么

 if ('undefined' !== typeof console){console.log(message); }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM