gpt4 book ai didi

JavaScript 无法在 IE 上运行

转载 作者:行者123 更新时间:2023-11-28 14:06:52 25 4
gpt4 key购买 nike

我有一个 JavaScript 代码片段,它在 Firefox 和 Safari 上运行得很好,但拒绝在 IE 上运行:

var drop= function(id)
{
if(document.getElementById("select1").value == "Ficha de pediatria"){
top.location.href = "print.jsp?id="+id+"&type=2";
}
else if(document.getElementById("select1").value == "Ficha normal"){
top.location.href = "print.jsp?id="+id+"&type=1";
}
}

<select id="select1" name="select1" onChange="drop(id);return false;">
<option>Imprimir:</option>
<option>Ficha de pediatria</option>
<option>Ficha normal</option>
</select>

我修改了它,因为它有更多的 JSP 代码,但它保持不变。有人知道为什么它不能在 IE 上运行吗?

最佳答案

[编辑]抱歉。我在第一篇文章中引入了一个错误,因为我没有仔细查看您如何构建网址。我不应该删除 id 参数。我已经更新了代码,现在应该可以工作了。

试试这个:

function drop(ctl,id)
{
var value = ctl.options[ctl.selectedIndex].value;

if(value == "Ficha de pediatria"){
window.top.location.href = "print.jsp?id="+id+"&type=2";
}
else if (value == "Ficha normal"){
window.top.location.href = "print.jsp?id="+id+"&type=1";
}
}

<select id="select1" name="select1" onChange="drop(this,id);return false;">
<option>Imprimir:</option>
<option>Ficha de pediatria</option>
<option>Ficha normal</option>
</select>

[编辑]一些解释...

我认为问题在于它如何访问 DOM。我不认为 IE 在选择上有值属性。我认为你必须通过所选选项来实现它。另外,我不确定全局命名空间中是否有 top 属性,但您应该能够通过 window.top 获取它来设置位置。最后,我做了一点改进,通过指定 this 作为参数,您可以跳过元素查找并直接从作为参数传递的控件引用它。

关于JavaScript 无法在 IE 上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/257085/

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