Javascript在Chrome和Safari中无法启动

时间:2014-03-11 12:23:08

标签: javascript google-chrome safari

我有一些javascript在Chrome和Safari中无法启动,但在Firefox和IE中运行良好。我似乎无法弄清问题是什么。我尝试从选项中删除OnClick事件处理程序并将其更改为Select中的OnChange,但这也不起作用。不确定是否仅仅是一个轻微的语法差异问题,我忽略了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>

1 个答案:

答案 0 :(得分:0)

Chrome不支持选项标记上的onclick事件。请改用select-tag上的onchange事件。

见这里: javascript onclick alert not working in chrome