Javascript没有在IE上运行 [英] Javascript not running on IE

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

问题描述

我有一个在Firefox和Safari上运行得很好的javascript,但拒绝在IE上运行

I Got a javascript that runs very well on firefox and safari, but refuses to run on 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上运行?

I trimed this as it had more JSP code but it' remained the same. Anyone got any idea why it's not running on IE?

推荐答案

抱歉。我在第一篇文章中介绍了一个错误,没有仔细查看你是如何构建你的网址的。我不应该删除 id 参数。我已经更新了代码,现在应该可以使用了。

Sorry. I introduced an error with my first post by not carefully looking at how you are constructing your url. I shouldn't have removed the id parameter. I've updated the code and it should work now.

试试这个:

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>

一些解释......

A bit of explanation...

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

I think the issue is how it is accessing the DOM. I don't think that IE has a value property on a select. I think you have to get at it via the selected option. Also, I'm not sure that there is a top property in the global namespace, but you should be able to get at it via window.top to set the location. Finally, I made a slight improvement in that by specifying this as the argument, you can skip the element lookup and reference it directly from the control passed as the argument.

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

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