运行 js 文件中与 i.e9 v 的所有其他浏览器有关的特定代码

running specific code in js file pertaining to i.e9 v's all other browsers

所以它归结为这一行代码...我基本上是在尝试在我的代码中创建一个部分,说明如果 i.e9 执行此操作,但如果不执行此操作...这是代码...

('.fa-phone, .bg-darkPink').parent().on('click', function () {
      $('.submenu-ctn').fadeTo(0, 0);



<<--IF I.E9 OR BELOW DO THIS THING--->>
    $('#menu').multilevelpushmenu({
            Collapsed: true



              });
          <<--END OF I.E9 OR BELOW THING ----->>

  <<--I.E9 MUST ALSO IGNORE THIS LINE IN THE SCRIPT --->> 
  $( '#menu' ).multilevelpushmenu( 'collapse' );

$MORE CODE 
$MORE CODE

它是与按钮关联的一串函数的一部分。出于某种原因,即 e9 不喜欢该函数,但它以另一种方式喜欢它。这里的任何帮助都会很棒...

p.s 我正在使用 modernizr 2.6.2,所以一直在阅读它的特征检测功能,但无法理解它,请有人让我摆脱痛苦;p

解决方案开始编辑

到目前为止我有这个...

 $('.fa-phone, .bg-darkPink').parent().on('click', function () {
      $('.submenu-ctn').fadeTo(0, 0);
      $('.submenu-ctn').fadeTo(3000, 1); 
      $("#colorscreen").remove();
      $("body").append('<div id="colorscreen" class="animated"></div>');
      $("#colorscreen").addClass("fadeInUpBigCS");
      $(".tile-area-main").css({width: "720px",opacity:1}).load("contact-page.html #contact-form");
      $.getScript("js/slider/slider-animations.js");
      $(".submenu-ctn").load("contact-page.html .submenu-contact");
      $('.nav-toggle').removeClass('active');
      $(this).addClass('active');  

      if(browser.name=='msie'&&browser.version<=9) { 
       $('#menu').multilevelpushmenu({Collapsed: true}); 
       }else { 
       $( '#menu' ).multilevelpushmenu( 'collapse' ); }

});

您可以在 html 中使用条件注释:

<!--[if lte IE 9]>
  // Include script for ie9 and less here
<![endif]-->

更新:

您可以在Script中使用navigator对象来检测是否是ie9或以下

navigator.appVersion

它return这个:

clientVersion (platform; information; extraInformation)

示例:

5.0 (compatible; MSIE 5.5; Windows 98; Win 9x 4.90)

检查以下内容link

代码如下:

var flag = false;
function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp. );
  }
  return rv;
}
function checkVersion()
{
  var msg = "You're not using Internet Explorer.";
  var ver = getInternetExplorerVersion();

  if ( ver > -1 )
  {
    if ( ver == 9.0 ) 
      flag = true
    else
      flag = false
  }else{
  flag = false
}
}

如果标志为真,现在检查你的函数调用函数,否则跳过

更新 3:

var ms_ie = false;
var ua = window.navigator.userAgent;
var old_ie = ua.indexOf('MSIE ');
var new_ie = ua.indexOf('Trident/');

if ((old_ie > -1) || (new_ie > -1)) {
    ms_ie = true;
}

if ( ms_ie ) {
    //IE specific code goes here
}

试试这个代码

$('.fa-phone, .bg-darkPink').parent().on('click', function () {
      $('.submenu-ctn').fadeTo(0, 0);
      $('.submenu-ctn').fadeTo(3000, 1); 
      $("#colorscreen").remove();
      $("body").append('<div id="colorscreen" class="animated"></div>');
      $("#colorscreen").addClass("fadeInUpBigCS");
      $(".tile-area-main").css({width: "720px",opacity:1}).load("contact-page.html #contact-form");
      $.getScript("js/slider/slider-animations.js");
      $(".submenu-ctn").load("contact-page.html .submenu-contact");
      $('.nav-toggle').removeClass('active');
      $(this).addClass('active');  

// code started here

var ms_ie = false;
    var ua = window.navigator.userAgent;
    var new_ie = ua.indexOf('Trident/5');   //only for ie9

    if ((new_ie > -1) {
        ms_ie = true;
    }

    if ( ms_ie ) {
        $('#menu').multilevelpushmenu({Collapsed: true}); 
        }else{
    $( '#menu' ).multilevelpushmenu( 'collapse' );
    }
    });

来自 How can you detect the version of a browser?,第二个答案,使用 if

if(browser.name=='msie'&&browser.version<=9)
   //do your stuff