JavaScript 可以在 Firefox 上运行,但不能在 Chrome 和 IE6 上运行

标签 javascript internet-explorer firefox getelementbyid

我的 JavaScript 在 Firefox 3.x.x 中工作正常,但在 IE*、Chrome、Safari 中不起作用。调用函数之前进行简单的警报工作。这是代码

function showDiv(div){
 //alert(div);
 document.getElementById(div).style.visibility='visible';
 document.getElementById(div).style.height='auto';
 document.getElementById(div).style.display='block';}
function hideDiv(div){
 //alert(div);
 document.getElementById(div).style.visibility='hidden';
 document.getElementById(div).style.height='0px';
 document.getElementById(div).style.display='none';
}

这是html页面代码

<td align="center"><a onclick="showDiv('<?=$val['keyname']?>')" style="cursor:pointer;">Edit</a></td>

如果我输入 alert()之前showDiv('<?=$val['keyname']?>')然后显示警告框,但在除火狐之外的其他浏览器中未调用该函数

请告诉我解决方案。

最佳答案

我觉得语法没问题。

确保文档中不存在具有相同 ID 的多个元素,并且您的元素 ID 有效。

关于JavaScript 可以在 Firefox 上运行,但不能在 Chrome 和 IE6 上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3675870/

相关文章:

javascript - jQuery 的嵌套 Accordion 菜单问题

excel - IE上的VBA单击按钮

javascript - 样式形成 Angular Material 不适用于 IE 11

html - 为什么 chrome 不对齐此文本?

html - Firefox 绝对位置防止按钮点击

firefox - 创建您自己的自定义浏览器

javascript - 远程脚本可以向托管脚本的服务器发出请求吗?同源政策

javascript - 是否可以通过浏览器在 JavaScript 中检测硬件加速?

javascript - 我如何在 div 之间切换

internet-explorer - IE 和 Firefox 之间的 CSS 区别是什么