Jquery IE错误

时间:2011-07-08 21:39:17

标签: javascript jquery internet-explorer

我有一些Jquery写的在firefox和chrome中运行正常但在IE中引发了错误。

以下是代码部分,当取出时允许脚本的其他部分正确运行...(否则整个文件不会被IE读取)

var product_qty_is_zero = ExternalCustom_product_qty_is_zero; //'import' external variable from view.phtml
var option_is_selected = false;
var options_exist = false;
if(  ($(".options-container-big").length > 0) || ($(".options-container-small").length > 0)  )
    options_exist = true;   

$('#main-button-btn-cart').mouseenter(function() {
        //@ controlling backorder message
        if(product_qty_is_zero)
        {
            $('#select-product-reminder').slideDown(300);
            $('#select-product-reminder').text("product is purchaseable but on backorder");
            $('#select-product-reminder').css("background-color", "#c3c3c3");
        }                                          
});

$('#main-button-btn-cart').click(function() {
    if(!option_is_selected && options_exist) 
        $('#select-product-reminder').slideDown(300);
    else
        productAddToCartForm.submit();
});



 $('#select-product-reminder').slideUp(300);
  option_is_selected = true;

 var image_info = ExternalCustom_image_info; //'import' variable from media.phtml
  var image_link;
  var $selected_value_variation = $('.selected').html();
  for (var i = 0; i < image_info.length; i++) 
  {
        if(image_info[i][0] == $selected_value_variation)
            image_link = image_info[i][1];
  }
  $('#main-image').attr("href", image_link);

如果有人可以查看它,看看IE是否有任何常见的错误标记并给我一些提示,我们将不胜感激!

注意*我已经尝试了类和div扩展名,例如      $( 'div.options容器-大') 和      $( 'DIV#主按钮BTN-车')

2 个答案:

答案 0 :(得分:0)

只有在没有可能导致打嗝的更多信息的情况下我才能看到:

productAddToCartForm.submit();

如果IE不知道那是什么,它可能会失败。尝试用JQuery安全选择器语法包装它:

$(productAddToCartForm).submit();

或:

// Assuming you have a <form id="productAddToCardForm"...>
$('#productAddToCartForm').submit();

答案 1 :(得分:0)

你已经说过,IE在行

上没有定义console
if (console) { ... // Error if `console` is not defined anywhere

这是非常正确的。 console不是浏览器上保证的内置对象,尽管许多浏览器都提供它。你可能想要

if (typeof console !== "undefined") { ...

...来代替。我们没有采用,我们只是检查它是否存在。

这是JavaScript的一个区域,可能会让人感到有些困惑,但基本上,如果你试图获取一个真正未在任何地方声明的非限定引用的值,例如

if (foo) { ...

......这是一个错误。这可能会让人感到困惑的原因是您可以在完全相同的情况下分配给foo,并且它将是有效的(它将是The Horror of Implicit Globals,但是有效)。同样,您可以愉快地获取从未定义过的对象属性的值:

var obj = {};
if (obj.foo) { ... // Not an error, we just don't go into the body of the `if`

...因为那不是一个不合格的参考。但是对于不合格的引用,这是一个错误。

那么为什么console在IE8和IE9上不合格,两者都有console.log等等?因为除非您打开开发人员工具,否则IE8和IE9没有console [或console.log] 。奇怪但真实。错了,但是没错。 :-)打开开发人员工具,它们基本上是IE8和IE9的插件,可以即时添加console对象。 (关于Stack Overflow的this other question (and answer)更多内容。)