php - IE9 中的 Heisenbug

标签 php jquery html internet-explorer-9

好的 StackOverflow - 这是一个奇怪的。

问题

所以我有一个“按钮”(实际上只是一个带有 javascript onclick 监听器的 div),它在页面加载时通过 json 从数据库中获取其文本。 (考虑到应用程序,这是有道理的)。我们不支持 IE < 9。

问题是 div 中的文本不会显示在 IE9 的新实例中。但是,当我打开开发人员控制台(试图找出问题出在哪里)并刷新页面时,IE 就好像什么都没有出错一样并正确填充按钮文本。它适用于所有其他浏览器。

什么。

代码

所以这是我在 PHP 中的内容:

<div class="dark-button notification-button" data-notification="NOTIF_A">
    <span class="float-right">&#9654;</span>
</div>

Javascript(使用 Jquery 1.8.0):

$('document').ready(refreshNotificationButtons('.notification-button'));
function refreshNotificationButtons(buttons){
    var buttons = typeof buttons != 'object' ? $('.notification-button') : buttons;
    var allNotifications = {};
    var buttonsCount = 0;
    buttons.each(function(){
        var button = $(this);
        if(typeof button.attr('id') == 'undefined') button.attr('id', 'notif-button-' + buttonsCount);
        buttonsCount ++;
        if(typeof allNotifications[button.attr('data-notification')] == 'undefined'){
            allNotifications[button.attr('data-notification')] = [button.attr('id')];
        } else {
            allNotifications[button.attr('data-notification')].push(button.attr('id'))
        }
    });
    $.get(
        '/notifications/get_notifications/' + $.map(allNotifications, function(x, abbr){return abbr}).join(','),
        '',
        function(data){
            $(data).each(function(){
                if (typeof allNotifications[this.Notification.NotificationAbbr] != 'undefined'){
                    console.log(this); //debug
                    buttonEl = $('#' + allNotifications[this.Notification.NotificationAbbr]);
                    if(this.Notifications_User.UserID != null) buttonEl.addClass('notification-button-remove');
                    buttonEl.attr('data-notification-id', this.Notification.Notifications_TableID);
                    buttonEl.append($('<span class="notification-button-signup-span">' + this.Notification.EnableText + '</span><span class="notification-button-remove-span">' + this.Notification.DisableText + '</span>'));
                }
            });
        },
        'json'
    );

图片

打开开发控制台前的按钮:

Button before opening dev console

打开开发控制台并刷新后的按钮:

Button after opening dev console

结论

有什么想法吗?如果您想查看更多代码,我很乐意发布!提前致谢。

最佳答案

如上文所述,console.log() 在没有打开的控制台可写入时在 IE 中无法正常工作。

您可以删除对 console 的调用,或者添加此插件(由 Paul Irish 开发)

http://paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/

关于php - IE9 中的 Heisenbug,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11942871/

相关文章:

javascript - 向表中添加动态数据

javascript - 如何将 jquery 代码转换为可重用的插件/函数

javascript - 在边界框内拖动和缩放图像

php - 在 MySQL 的同一个 WHERE 上使用来自 PHP 的两个变量

javascript - 更改同一系列数据中数据的条形颜色

jquery - 将样式设置为表格单元格的动画 div 宽度

html - 使用 flex 从列和内部列行中分离/网格化,并在中心的一列中对齐图像

大型代码库中的 Javascript,将颜色设置为不可变?

php - 节点更新 : getting the old value

php - 组合Mysql子查询