在IE8中工作的Javascript [英] Javascript working in IE8

查看:76
本文介绍了在IE8中工作的Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





任何人都可以提供帮助



我已经建立了javascript并提供了一些帮助,但是它在IE8中不起作用(在Chrome中工作正常)



由于XP上的工作电脑,我需要它在IE8中工作。



我用google搜索了probelm,它与object.keys和foreach,filter和reduce有关。



真的不知道下一步该怎么办



<% @ LANGUAGE =JAVASCRIPTCODEPAGE =1252%> 
<!DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Transitional // ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
< html xmlns =http://www.w3.org/1999/xhtml>
< head>

< script type =text / javascript>


var price = [
{type:'monthly',box:'Sky HD',product:'Platinum',price:'10'},
{类型:'每月',包装盒:'Sky HD',产品:'黄金',价格:'20'},
{类型:'每月',包装盒:'Sky HD',产品:'钻石',价格:'30'},
{类型:'每月',方框:'天空+',产品:'白金',价格:'40'},
{类型:'每月',包装盒:'Sky +',产品:'黄金',价格:'50'},
{类型:'每月',包装盒:'天空+',产品:'钻石',价格:'60'},
{类型:'每月',方框:'天空标准',产品:'白金',价格:'70'},
{类型:'每月',方框:'天空标准',产品: '黄金',价格:'80'},
{类型:'每月',包装盒:'天空标准',产品:'钻石',价格:'90'},
{类型:'每年',盒子:'Sky HD',产品:'Platinum',价格:'110'},
{类型:'每年',盒子:'Sky HD',产品:'Gold',价格:' 120'},
{类型:'每年',方框:'Sky HD',产品:'钻石',价格:'130'},
{类型:'annu ally',box:'Sky +',产品:'Platinum',价格:'140'},
{类型:'每年',盒子:'Sky +',产品:'Gold',价格:'150' },
{type:'annual',box:'Sky +',product:'Diamond',price:'160'},
{type:'annual',box:'Sky Standard',产品:'白金',价格:'170'},
{类型:'每年',方框:'天空标准',产品:'黄金',价格:'180'},
{类型:'每年',包装盒:'Sky Standard',产品:'钻石',价格:'190'}
];

var options = ['type','box','product'];


function setupOnLoad(){
options.forEach(function(opt){
var drop = document.querySelector('。'+ opt);
var unique = Object.keys(prices.reduce(function(x,y){return x [y [opt]] = 1,x;},{}));
unique.forEach(function(值){
var htmlOption = document.createElement('option');
htmlOption.value = htmlOption.innerText = value;
drop.add(htmlOption);
}) ;

drop.onchange = function(){
updatePrice();
};
});

updatePrice();
}

函数updatePrice(){
var matches = prices;
options.forEach(function(opt){
var drop = document.querySelector('。'+ opt);
matches = matches.filter(function(price){return price [opt ] == drop.value;});
});
document.querySelector('。price')。innerText = matches [0] .price;
};



< / script>

< style type =text / css>
div {margin:5px; }
select {width:200px; }
label {display:inline-block;宽度:100px; }
< / style>

< meta http-equiv =Content-Typecontent =text / html; charset = iso-8859-1/>
< title> Untitled Document< / title>
< / head>

< body onload =setupOnLoad();>

< div>
< label>类型< / label>
< select class =type>< / select>
< / div>
< div>
< label> Box< / label>
< select class =box>< / select>
< / div>
< div>
< label>产品< / label>
< select class =product>< / select>
< / div>
< div>
< label>价格< / label>
< span class =price>< / span>
< / div>
< / body>

< / html>

解决方案

我无法在IE8中测试此解决方案,也许这个解决方案也不会起作用。

无论如何,可能值得研究这篇文章:因此,您需要动态填写下拉菜单 [ ^ ]



很抱歉无法验证它是否适用于IE8,但至少你有一个可下载的演示版本,可以快速轻松地进行测试。

Hi,

Can anyone help please

I have built javascript with some help, but it doesn't work in IE8 (works fine in Chrome)

I need it to work in IE8 due to work computers on XP.

I have googled the probelm, and its to do with object.keys and foreach, filter and reduce.

Really not sure where to go next

<%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
<!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>

<script type="text/javascript">


var prices = [
    { type: 'monthly', box: 'Sky HD', product: 'Platinum', price: '10' },
    { type: 'monthly', box: 'Sky HD', product: 'Gold', price: '20' },
    { type: 'monthly', box: 'Sky HD', product: 'Diamond', price: '30' },
    { type: 'monthly', box: 'Sky+', product: 'Platinum', price: '40' },
    { type: 'monthly', box: 'Sky+', product: 'Gold', price: '50' },
    { type: 'monthly', box: 'Sky+', product: 'Diamond', price: '60' },
    { type: 'monthly', box: 'Sky Standard', product: 'Platinum', price: '70' },
    { type: 'monthly', box: 'Sky Standard', product: 'Gold', price: '80' },
    { type: 'monthly', box: 'Sky Standard', product: 'Diamond', price: '90' },
    { type: 'annually', box: 'Sky HD', product: 'Platinum', price: '110' },
    { type: 'annually', box: 'Sky HD', product: 'Gold', price: '120' },
    { type: 'annually', box: 'Sky HD', product: 'Diamond', price: '130' },
    { type: 'annually', box: 'Sky+', product: 'Platinum', price: '140' },
    { type: 'annually', box: 'Sky+', product: 'Gold', price: '150' },
    { type: 'annually', box: 'Sky+', product: 'Diamond', price: '160' },
    { type: 'annually', box: 'Sky Standard', product: 'Platinum', price: '170' },
    { type: 'annually', box: 'Sky Standard', product: 'Gold', price: '180' },
    { type: 'annually', box: 'Sky Standard', product: 'Diamond', price: '190' }
];

var options = ['type','box','product'];


function setupOnLoad() {
    options.forEach(function(opt) {
        var drop = document.querySelector('.'+opt);
        var unique = Object.keys(prices.reduce(function(x,y) { return x[y[opt]] = 1, x; }, {}));
        unique.forEach(function(value) {
            var htmlOption = document.createElement('option');
            htmlOption.value = htmlOption.innerText = value;
            drop.add(htmlOption);
        });

        drop.onchange = function() {
            updatePrice();
        };
    });

	updatePrice();
}

function updatePrice() {
	var matches = prices;
    options.forEach(function(opt) {
        var drop = document.querySelector('.'+opt);
    	matches = matches.filter(function(price) { return price[opt] == drop.value; });
    });
    document.querySelector('.price').innerText = matches[0].price;
};



</script>

<style type="text/css">
div { margin: 5px; }
select { width: 200px; }
label { display: inline-block; width: 100px; }
</style>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body onload="setupOnLoad();">

<div>
    <label>Type</label>
    <select class="type"></select>
</div>
<div>
    <label>Box</label>
    <select class="box"></select>
</div>
<div>
    <label>Product</label>
    <select class="product"></select>
</div>
<div>
    <label>Price</label>
    <span class="price"></span>
</div>
</body>

</html>

解决方案

I am not in the position to test this solution in IE8, so maybe this solution will not work either.
In any case it might be worth looking into this article: So You Need To Fill a Dropdown Dynamically[^]

Sorry for not being able to verify if it works in IE8, but at least you have a downloadable demo that makes it fast and easy to test.


这篇关于在IE8中工作的Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆