2012-03-27 55 views
0

我希望有一些新鮮的眼睛可以看到我失蹤的東西。我有一個頁面(在WordPress網站中),在Firefox,Chrome,Opera & Safari中運行良好,但不在IE中。爲了查看它是否執行了任何操作,我在document.ready函數的第一行中放置了一個警報,並且它顯示在除IE之外的所有瀏覽器中(在IE7和IE9上嘗試過)。爲什麼javascript/jquery會在所有瀏覽器中執行但IE?

這裏是document.ready函數。任何人都可以看到任何理由,爲什麼這不會在IE中執行?

<!-- language: lang-js --> 
$(document).ready(function() { 
    alert('in .ready function'); 
    //$("input:text:visible:first").focus(); 
    $(window).scrollTop(); 
    // $(this).scrollTop(0); 
    $("#u_phone").mask("(999) 999-9999"); 
    $('#fab_result').hide(); 
    $('#fab_header').hide(); 
    $('#optIn').hide(); 
    $('div.message').show(); 
    $('#mymap').show(); 
    $("#my_form").validate(); 
    if ($("#u_firstname").length > 0) { 
     $("#u_firstname").rules("add", { 
      required: true, 
      minlength: 5, 
      messages: { 
       required: " This field is required " 
      } 
     }); 
    } 
    if ($("#u_email").length > 0) { 
     $("#u_email").rules("add", { 
      required: true, 
      email: true, 
      messages: { 
       required: " This field is required " 
      } 
     }); 
    } 
    if ($("#u_phone").length > 0) { 
     $("#u_phone").rules("add", { 
      required: true, 
      messages: { 
       required: " This field is required " 
      } 
     }); 
    } 
    if ($("#u_custom_20").length > 0) { 
     $("#u_custom_20").rules("add", { 
      required: true, 
      minlength: 3, 
      messages: { 
       required: " This field is required " 
      } 
     }); 
    } 
    var mapsterOpts = { 
     fillOpacity: 0.5, 
     render_highlight: { 
      fillColor: '2aff00', 
      stroke: true, 
      strokeWidth: 2 
     }, 
     render_select: { 
      fillColor: 'ff000c', 
      stroke: false 
     }, 
     fadeInterval: 5000, 
     isSelectable: false 
    }, 
     mainOpts = $.extend({}, mapsterOpts, { 
      mapKey: 'province', 
      onClick: clickMain 
     }), 
     detailOpts = $.extend({}, mapsterOpts, { 
      onClick: clickDetail 
     }); 
    $('#canada-map').mapster(mainOpts); 
}); 
+0

你是什麼意思不執行?在頂部火警?你能從IE的錯誤控制檯粘貼一些信息嗎? – Fresheyeball 2012-03-27 04:15:50

+0

啓用腳本調試。在頁面刷新上查找語法錯誤。 – 2012-03-27 04:17:06

+0

您的腳本是否會創建一個在您的IE瀏覽器中不起作用的畫布標籤?如果是這樣的話,將其包裝在條件標籤中以檢查瀏覽器 – mikevoermans 2012-03-27 04:26:32

回答

-1

問題是在這裏:

使用VAR聲明變量,不要使用逗號(,),而不是(;)

改變這一點:

var mapsterOpts = { 
    fillOpacity: 0.5, 
    render_highlight: { 
     fillColor: '2aff00', 
     stroke: true, 
     strokeWidth: 2 
    }, 
    render_select: { 
     fillColor: 'ff000c', 
     stroke: false 
    }, 
    fadeInterval: 5000, 
    isSelectable: false 
}, 
    mainOpts = $.extend({}, mapsterOpts, { 
     mapKey: 'province', 
     onClick: clickMain 
    }), 
    detailOpts = $.extend({}, mapsterOpts, { 
     onClick: clickDetail 
    }); 
$('#canada-map').mapster(mainOpts); 

var mapsterOpts = { 
     fillOpacity: 0.5, 
     render_highlight: { 
      fillColor: '2aff00', 
      stroke: true, 
      strokeWidth: 2 
     }, 
     render_select: { 
      fillColor: 'ff000c', 
      stroke: false 
     }, 
     fadeInterval: 5000, 
     isSelectable: false 
    }; 
    var mainOpts = $.extend({}, mapsterOpts, { 
     mapKey: 'province', 
     onClick: clickMain 
    }); 
    var detailOpts = $.extend({}, mapsterOpts, { 
     onClick: clickDetail 
    }); 
    $('#canada-map').mapster(mainOpts); 
+0

'var a,b,c,d;'完全合法 - 不確定爲什麼你會建議在最佳實踐中只使用一個'var 'per'function' – gnarf 2012-03-27 05:18:35

+0

是的,謝謝,我完全忘了它 – pylover 2012-03-27 05:21:47

相關問題