[英]This code works in all other browsers except in IE
This works fine in all browsers except IE can anyone explain why so I can fix it. 这在所有浏览器中都可以正常工作,但IE谁都可以解释原因,因此我可以修复它。 I am displaying the index of a javascript object based on the index of the selected index of my dropdown list
我正在根据下拉列表中所选索引的索引显示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: HTML:
<div>
<select id="produceList">
<option>make a selection</option>
</select>
console.log
throws an error in IE, so to be on the safer side DO NOT use console.log with out checking if browser supports it or not. console.log
在IE中引发错误,因此为了安全起见,请勿在未检查浏览器是否支持console.log的情况下使用console.log。
try{
if(console && console.log) console.log('message')
}catch(e){}
OR 要么
if ('undefined' !== typeof console){console.log(message); }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.