简体   繁体   English

点击事件在Chrome和FireFox中无法正常运行,但在IE浏览器中可以正常运行

[英]On Click Event is not working in Chrome and FireFox, but works fine in the IE browers

I want the user to click on a td in a table to call a javascript function, but its working fine in the IE, but not in the chrome and firefox browser. 我希望用户单击表中的td来调用javascript函数,但是它在IE中可以正常工作,但在chrome和firefox浏览器中却不能。

<td id="tdMon" class="space15" style="cursor: pointer;" onclick="HandleClick1(this);">
    <div id="dvDay1" runat="server">
          <div class="booking-day">
             <asp:Label ID="lblDay1" runat="server" Text=""></asp:Label>
             <asp:LinkButton ID="lnk1" runat="server" Text="" OnClick="lnk1_Click" CommandName="click"
             CommandArgument=""></asp:LinkButton>
             |&nbsp
             <asp:Label ID="lblhr1" runat="server" Text="-- hr(s)" ForeColor="red"></asp:Label>
       </div>
         </div>
</td>

-- bottow of the page -- -页面底部-

<script language='javascript' type='text/javascript'>
 function HandleClick1(objTD) {
            var lnk = objTD.getElementsByTagName("a");
            if (lnk[0].disabled == false)
                document.getElementById('<%=btn1.ClientID %>').click();
            else
                return false;
        }
</script>

It's a bad idea to have inline functions/styles. 具有内联函数/样式是一个坏主意。 Taking into account you already have an ID for your td: 考虑到您已经拥有您的td的ID:

function init(){
    document.getElementById('tdTue').onclick=function(){};
}
window.onload=init;

If you want to go for something like jquery, this is probably a better model. 如果您想使用类似jquery的东西,这可能是一个更好的模型。 I'm sure the function was just an example. 我确定该功能只是一个例子。 This only triggers a click on TDs that have a data-link-rel attribute and it searches for the equivalent link. 这仅触发对具有data-link-rel属性的TD的单击,并搜索等效的链接。

$(function () {
  $("table").on("click", "td[data-link-rel]", function () {
      var linkRel = $(this).data("link-rel"),
          selector = "a[data-link=" + linkRel + "]";
      $(selector).trigger('click');

  });

  $("a").on("click", function () {
      $("<li> I clicked on " + $(this).text() + "</li>").appendTo('ul');
  });

});

JSFiddle with markup: http://jsfiddle.net/D8yg9/ 带有标记的JSFiddle: http//jsfiddle.net/D8yg9/

暂无
暂无

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

相关问题 JavaScript无法在IE和Firefox中运行,在Chrome中运行良好 - JavaScript not working in IE and Firefox, works fine in Chrome onclick事件在firefox中不起作用,但在IE中可以正常工作 - onclick event not working in firefox but works fine in IE 事件在IE6中未定义,但在Firefox,Chrome等中正常运行 - Event is undefined in IE6 but works fine in Firefox, Chrome etc 解决“ onpopstate”事件的方法,该事件在chrome中不起作用,但在IE和FireFox中可以正常工作 - Solution for, “onpopstate” event which is not working in chrome, but working fine in IE and FireFox Bootstrap图像响应在IE和Firefox中不起作用,但在Google Chrome中正常运行 - Bootstrap image responsive not working in IE and Firefox but works fine in Google Chrome jQuery Datepicker在IE中不起作用,与Firefox和Chrome兼容 - JQuery Datepicker not working in IE, Works fine with Firefox and Chrome JavaScript UTC到本地时间的转换在IE和Firefox中不起作用,但在Chrome上运行良好 - JavaScript UTC to localtime conversion not working in IE & Firefox, but works fine for Chrome Protractor actions().mouseMove 命令不适用于 firefox 和 IE,对于 chrome 它工作正常 - Protractor actions().mouseMove command not working for firefox and IE, for chrome it works fine ng-click在IE中不起作用,但在CHROME中可以正常工作 - ng-click not working in IE but works fine in CHROME javascript出现IE错误,在Firefox和Chrome上正常运行 - IE error with javascript that works fine on Firefox and Chrome
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM