onclick 在 ie 中不起作用

onclick isn't working in ie

我有以下代码:

<input class="button button-blue" type="button" onclick="jQuery.fancybox.close(); " value="Close">

在 ie 中,当我单击按钮时,onclick 事件处理程序不起作用。 "doesn't work" 表示花式框对话框不会关闭。但是一旦我使用 f12 更改了 onclick 值(即在 jQuery.fancybox.close() 之后添加 space),onclick 事件处理程序就会开始工作。

注:

关于如何解决问题有什么建议吗?

$.fancybox({
      'modal': true,
       height: '10%', minHeight: '60',
       'content': "<div style=\"margin:10px;\">"
       + 'Your message has been sent.'
       + "<div style=\"text-align:center;margin-top:10px;\"><input     class=\"button button-blue\" type=\"button\" onclick=\"jQuery.fancybox.close();  Backbone.pubSub.trigger('myContentShowHide');\" value=\"My Content\"></div>"
       + "<div style=\"text-align:center;margin-top:10px;\"><input     class=\"button button-blue\" type=\"button\" onclick=\"jQuery.fancybox.close();   \" value=\"Close\"></div>"
});

您已经安装了 jQuery,它是专门为规范化任何跨浏览器问题而设计的。

因此摆脱内联事件处理程序并改用 jQuery 事件处理程序。由于调用此代码时按钮元素尚不存在,因此您需要使用事件委托方法...

jQuery(document).ready(function($) {

    $('body').on('click', 'input.button[value="Close"]', function() {
        $.fancybox.close();
    });

});

参见:http://api.jquery.com/on/

演示:http://jsfiddle.net/6k1o7amL/

避免使用内联事件处理程序。使用 jQuery 将事件绑定到按钮,如下所示:

jQuery(document).ready(function(){

   jQuery('.button').click(function(e){
      jQuery.fancybox.close();
      e.preventDefault();
   });

});