【问题标题】:Onclick not working in IE or Firefox but does work in ChromeOnclick 在 IE 或 Firefox 中不起作用,但在 Chrome 中起作用
【发布时间】:2016-05-05 08:23:22
【问题描述】:

我正在尝试让 Onclick 在 IE 或 Firefox 中工作,但无论我做什么它都不起作用,除了在 Chrome 中。

<h2 onclick="javascript:window.location.href='<?php echo $cbox['read_more_url'];?>';" style="cursor: pointer;"><?php echo $cbox['title'];?></h2> 
        <img src="<?php echo $cbox['image']['sizes']['gallery_large'] ?>" height="<?php echo $cbox['image']['sizes']['gallery_large-height'] ?>" width="<?php echo $cbox['image']['sizes']['gallery_large-width'] ?>" alt="<?php echo $cbox['title']; ?>" onclick="javascript:window.location.href='<?php echo $cbox['title_url'];?>';" style="cursor: pointer;"/>

我也试过 location.href 和 window.location 但还是不行。这是网站http://www.tradewindgroup.com.au/ 代码指的是 3 个标头 Construction - Plumbing - 以及下面的图片,它在 Chrome 中运行良好。

谢谢

【问题讨论】:

标签: javascript php html google-chrome onclick


【解决方案1】:

更新你的脚本:

<h2 onclick="redirectme('<?php echo $cbox['read_more_url'];?>');" style="cursor: pointer;"><?php echo $cbox['title'];?></h2> 
<img src="<?php echo $cbox['image']['sizes']['gallery_large'] ?>" height="<?php echo $cbox['image']['sizes']['gallery_large-height'] ?>" width="<?php echo $cbox['image']['sizes']['gallery_large-width'] ?>" alt="<?php echo $cbox['title']; ?>" onclick="redirectme('<?php echo $cbox['title_url'];?>');" style="cursor: pointer;"/>

在 javascrpt 中创建如下函数:

function redirectme(myurl) {
               window.location="http://" + myurl;
            }

示例如下:

<html>
<body>

<h2 onclick="redirectme('google.com');" style="cursor: pointer;">Google</h2>


<script type="text/javascript">
function redirectme(myurl) {
               window.location="http://" + myurl;
            }
</script>
</body>
</html>

【讨论】:

  • 我可以将 Javascript 添加到我的页面底部吗?
  • 我已对其进行了更新,但仍然无法在 Firefox 或 IE 中单击它们。在铬中工作。这很奇怪。
  • 我已经添加了完整的例子...用我的检查你的 html
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-08-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-04
  • 2011-05-03
相关资源
最近更新 更多