简体   繁体   English

div上的Javascript onclick函数仅适用于IE

[英]Javascript onclick function on div works only in IE

I have this code to call a function on a div when it's clicked: 我有这个代码在单击时调用div上的函数:

<div class="buttonsim" runat="server">
  $(document).ready(function () {
    $("div.buttonsim").click(function() {
      window.location.href("sim.aspx");
    });
  });

It works on IE but not on Chrome and Firefox> Am I doing something wrong? 它适用于IE但不适用于Chrome和Firefox>我做错了吗? Is it missing something? 它丢失了什么吗?

window.location.href is not a method, it should be window.location.href不是一个方法,它应该是

window.location.href = "sim.aspx";

If you really want to use a method, you can use assign() 如果你真的想使用方法,你可以使用assign()

window.location.assign("sim.aspx");

You need to actually set the window.location.href property as you are currently using it as a method : 您需要实际设置window.location.href属性,因为您当前正在将其用作方法:

    $("div.buttonsim").click(function() {
        window.location.href = "sim.aspx";
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM