[英]Javascript not Firing in Chrome and Safari
I have some javascript that won't fire in Chrome and Safari but works fine in Firefox and IE. 我有一些JavaScript无法在Chrome和Safari中启动,但在Firefox和IE中可以正常运行。 I cannot seem to figure out what the problem is.
我似乎无法弄清楚问题出在哪里。 I tried removing the OnClick event handler from the options and changing it to an OnChange in the Select, but that did not work either.
我尝试从选项中删除OnClick事件处理程序,然后将其更改为Select中的OnChange,但这也不起作用。 Not sure if it is just a matter of a slight syntax difference that I am omiting for Chrome and Safari or what it is:
不知道我只是忽略了Chrome和Safari的语法差异还是什么:
<script type="text/javascript">
var year = new Date();
var year1 =year.getFullYear() -1;
var year2 =year.getFullYear() -2;
var year3 =year.getFullYear() -3;
var year4 =year.getFullYear() -4;
var year9 =year.getFullYear() -9;
</script>
<script>
//When called, this finds the parameter that you pass to it
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = value;
});
return vars;
}
//This calls the above function to find the guid, then it redirects the page
function getGuidAndGo(a)
{
//Get the Guid
var myGuid = getUrlVars()["guid"];
switch(a)
{
case 1:
window.location = "https://dev-arenaweb.gocf.org/ContrReport_selectyr_internal.aspx?negnum=1&guid=" + myGuid;
break;
case 2:
window.location = "https://dev-arenaweb.gocf.org/ContrReport_selectyr_internal.aspx?negnum=2&guid=" + myGuid;
break;
case 3:
window.location = "https://dev-arenaweb.gocf.org/ContrReport_selectyr_internal.aspx?negnum=3&guid=" + myGuid;
break;
}
}
</script>
<head>
<body>
<div id="mainbg">
<span style="font-weight: bold; font-size: 18px;">Contribution Statement</span>
<span style="font-size: 16px;"><br />
</span>
<span style="font-size: 16px;">Please select a year for the Contribution Statement that you would like to view.</span>
<br />
<em>(A .pdf will be generated. May take a few seconds to load...)</em> <br />
<br />
<br />
<select>
<option value="#">Select a Year</option>
<option id="myYear1" onClick="getGuidAndGo(1)" value="">
<script type="text/javascript">document.write(year1);</script>
</option>
<option id="yYear2" onClick="getGuidAndGo(2)" value="">
<script type="text/javascript">document.write(year2);</script>
</option>
<option id="myYear3" onClick="getGuidAndGo(3)" value="">
<script type="text/javascript">document.write(year3);</script>
</option>
</select>
Chrome does not support the onclick event on option-tags. Chrome浏览器不支持选项标签上的onclick事件。 Use the onchange event on the select-tag instead.
请在选择标签上使用onchange事件。
See here: javascript onclick alert not working in chrome 请参阅此处: javascript onclick警报在Chrome中不起作用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.