1

我得到了以下 javascript 代码。基本上,它可以在 FF 和 IE 上使用开发者工具。

$(function(){
    console.log("it is ok");
    var mybutton="";

    alert("ready1");
    $('button[name="delorder"]').click(function(){

        console.log($(this).val()+"hay i got a click");
        mybutton=$(this).val();
        alert("a click1");
        $.ajax({
            type:'POST',
            url:'deleteorderitem.php',
            data:mybutton,
            success:function(result){

                if((result.indexOf("t") < 3) && (result.indexOf("t") >= 0)){                    

                    $('#orderresult').html(result);                 

                    console.log("i am 3 ");
                    console.log("index of t is "+result.indexOf("t"));
                }else{
                    console.log("i am 4");                      
                    console.log("index of t is "+result.indexOf("t"));
                    $('#divOrderButton').hide();
                    $('#orderresult').html("");
                    $('#divNoinfo').html("There is no record to display at the moment.");
                    $('#divNoinfo').show(); 
                    $('#divOrder').hide();
                }
            }
        });
    });
});
</script>

但是,它不适用于 IE(没有开发人员工具)。所以,任何建议将不胜感激。谢谢

4

3 回答 3

2

主要是因为

console.log()

Windows IE8 及以下版本在开发者工具未打开时没有控制台对象。

要么注释掉控制台的行。或者预先创建控制台对象。

试试这个......不确定这是否是正确的方法......

var alertFallback = true;
   if (typeof console === "undefined" || typeof console.log === "undefined") {
     console = {};
     if (alertFallback) {
         console.log = function(msg) {
              alert(msg);
         };
     } else {
         console.log = function() {};
     }
   }

如果控制台对象不存在,这将创建它。

于 2012-11-19T18:04:31.420 回答
1

如果您说如果没有打开开发人员工具就无法工作,(除非我弄错了)那是因为您拥有所有这些console.log,这一定是导致它崩溃的原因。

在主 JS 文件的最顶部尝试这样的操作,以防止在 IE 中出现这种情况。

if (typeof (console) === 'undefined' || !console) {
    window.console = {};
    window.console.log = function () { return; };
}
于 2012-11-19T18:04:39.193 回答
0

我使用此功能为跨浏览器控制台日志编写日志:

/**
 *Log into the console if defined 
 */
function log(msg)
{       
    if (typeof console != "undefined") {
        console.log(msg);
    }       
}
于 2012-11-19T18:07:57.107 回答