gpt4 book ai didi

Javascript 在谷歌、火狐中工作,但在 IE9 中不工作

转载 作者:可可西里 更新时间:2023-11-01 14:45:04 25 4
gpt4 key购买 nike

这是一个简单的彩票随机生成器,适用于谷歌浏览器、火狐浏览器。但它在 Internet Explorer 9 中不起作用。

当我在 IE9 中使用调试功能时,它说我的 HTML 中的 myFunction()nullundefined。我不熟悉与 IE 一起使用的编码程序,因此非常感谢任何形式的帮助。

<!DOCTYPE htlm>
<html>

<title>LOTTERY</title>
<head>
<script>

function myFunction()
{

var myElement = document.getElementById("pwbx");
myElement.value = Math.floor(Math.random() * 11);

var myElement = document.getElementById("pwbx1");
myElement.value = Math.floor(Math.random() * 11);

var myElement = document.getElementById("pwbx2");
myElement.value = Math.floor(Math.random() * 11);

var myElement = document.getElementById("pwbx3");
myElement.value = Math.floor(Math.random() * 11);

var myElement = document.getElementById("pwbx4");
myElement.value = Math.floor(Math.random() * 11);

var myElement = document.getElementById("pwbx5");
myElement.value = Math.floor(Math.random() * 11);

};

</script>
<style>
.firenze {height: 100px; width: 300px;} .baltimore {border-radius: 11px;}
.baltimore{padding-left: 11px !important; padding-top: 11px !important}
.baltimore{height: 133px; width: 387px !important;}
.baltimore{border: solid 1px black !important;}
.como {border: solid 1px black !important;}
.como {height: 53px !important; width: 343px !important;}
.como {padding-left: 33px !important; padding-top: 18px !important}
.foxtrot1 {width: 130px !important;} .foxtrot1 {text-align: center !important;}
.echo1 {padding-left: 111px !important; padding-top: 7px !important; }
.jessie {padding-top: 63px !important;}
.como li {display: inline-block !important; vertical-align: top !important; float: left !important;}
.como li {margin: 3 !important;} .bravo {padding-left: 1px !important;} .bravo {font-size: 18px;}
.delta {border: solid 1px black !important;} .delta {height: 13px; width: 27px !important;}
.delta {padding-bottom: 13px;} .tango {padding-left: 1px !important;} .tango {font-size: 18px;}
.yankee {border: solid 1px black !important;} .yankee {height : 13px !important; width: 27px !important;}
.yankee {padding-bottom: 13px;} .sierra {padding-left: 1px !important;} .sierra {font-size: 18px;}
.uniform {border: solid 1px black !important;} .uniform {height: 13px !important; width: 27px !important;}
.uniform {padding-bottom: 13px;} .lima {padding-left: 1px !important;} .lima {font-size: 18px;}
.hotel {border: solid 1px black !important;} .hotel {height: 13px !important; width: 27px !important;} .hotel {padding-bottom: 13px;}
.romeo {padding-left: 1px !important;} .romeo {font-size: 18px;} .oscar {border: solid 1px black !important;}
.oscar {height: 13px !important; width: 27px !important;} .oscar {padding-bottom: 13px;} .zulu {padding-left: 1px !important;}
.zulu {font-size: 18px;} .golf {border: solid 1px black !important;} .golf {height: 13px !important; width: 27px !important;}
.golf {padding-bottom: 13px;} .power{font-weight: bold; font-size: 17px;} .power {padding-top: 4px;}
</style>
</head>
<body>

<div class = "firenze">
<div class = "baltimore">
<ul style="list-style-type: none" id = "dis" class = "como">
<li class = "delta"><output class = "bravo" type = "text" id = "pwbx"></output></li>
<li class = "yankee"><output class = "tango" type = "text" id = "pwbx1"></output></li>
<li class = "uniform"><output class = "sierra" type = "text" id = "pwbx2"></output></li>
<li class = "hotel"><output class = "lima" type = "text" id = "pwbx3"></output></li>
<li class = "oscar"><output class = "romeo" type = "text" id = "pwbx4"></output></li>
<li>Power Ball:</li>
<li class = "golf"><output class = "zulu" type = "text" id = "pwbx5"></output></li>
</ul>
<span class = "echo1"><input onclick = "myFunction();" value="Generate" type="submit" class = "foxtrot1"></span>

</div>
</div>
</body>
</html>

最佳答案

输出标签是 HTML5,可能无法在 IE9 上运行。您需要使用 HTML5 Shim 来增加向后兼容性。

这是在 jQuery 中工作的:

<div class = "firenze"> 
<div class = "baltimore">
<ul style="list-style-type: none" id = "dis" class = "como">
<li id = "delta" class = "delta"></li>
<li id = "yankee" class = "yankee"></li>
<li id = "uniform" class = "uniform"></li>
<li id = "hotel" class = "hotel"></li>
<li id = "oscar" class = "oscar"></li>
<li>Power Ball:</li>
<li id="golf" class = "golf"></li>
</ul>

<span class = "echo1"><input value="Generate" type="button" class = "foxtrot1" id="foxtrot1"></span>

</div>

</div>

JS

$("#foxtrot1").click(function(){  
$("#delta").html(randomToTwo());
$("#yankee").html(randomToTwo());
$("#uniform").html(randomToTwo());
$("#hotel").html(randomToTwo());
$("#oscar").html(randomToTwo());
$("#golf").html(randomToTwo());
});

function randomToTwo() {
return Math.floor(Math.random() * 11);
}

然后您可以添加隐藏的输入字段并设置为表单提交。

在 IE9 上测试和工作。

https://jsfiddle.net/abku3ns1/

关于Javascript 在谷歌、火狐中工作,但在 IE9 中不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31562812/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com