无法将javascript放入if else语句中

时间:2015-06-25 11:54:07

标签: javascript jquery css3

所以我有这个漂亮的小if if语句准备为ie9是一个僵尸浏览器,不支持像css3动画(通常)这是if语句....

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

} else {

}
$('.submenu-ctn').fadeTo(3000, 1);

我正在尝试将此脚本放入if else语句中......

$(document).ready(function() {
    $("body").on("click", ".slide", function(e) {
        e.preventDefault();
        $("#mission,#overview,#music,#potential,#people,#expression,#ethos,#cpd,#workshop,#team,#referrals,#local-links,#family,#mental,#palliative,#autism,#schools,#dementia,#private,#acreditations,#definitions,#research,#contact,#email,#phone,#contact-form,#finley,#councelling,#music-performance,#community-music,.slides").addClass("bounceOutUp");
        var that = this;
        setTimeout(function() {
            console.log($("#tam-content").load($(that).data("url") + ' ' + $(that).data("target")));
            $.getScript("js/slider/slider-animations.js");
        }, 1000);
    });
});

这样看起来像......

if ((old_ie > -1) || (new_ie > -1)) {
    ms_ie = true;
}
if (ms_ie) {    
    $("body").on("click", ".slide", function(e) {
        e.preventDefault();
        var that = this;
        setTimeout(function() {
            console.log($("#tam-content").load($(that).data("url") + ' ' + $(that).data("target")));
            $.getScript("js/slider/slider-animations.js");
        }, 1000);
    });
} else {
    $("body").on("click", ".slide", function(e) {
        e.preventDefault();
        $("#mission,#overview,#music,#potential,#people,#expression,#ethos,#cpd,#workshop,#team,#referrals,#local-links,#family,#mental,#palliative,#autism,#schools,#dementia,#private,#acreditations,#definitions,#research,#contact,#email,#phone,#contact-form,#finley,#councelling,#music-performance,#community-music,.slides").addClass("bounceOutUp");
        var that = this;
        setTimeout(function() {
            console.log($("#tam-content").load($(that).data("url") + ' ' + $(that).data("target")));
            $.getScript("js/slider/slider-animations.js");
        }, 1000);
    });

但由于某种原因它不起作用..我拿出了文件。已经位,我不认为这是问题但不确定..有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

HOOORAY !!

所以基本上这就是解决方案,关闭括号需要在if和else部分内部进行自然分割....

if ((old_ie > -1) || (new_ie > -1)) {
        ms_ie = true;
      }
      if ( ms_ie ) {
        $("body").on("click", ".slide", function(e){
        e.preventDefault();
        var that = this;
        setTimeout(function() {
        console.log($("#tam-content").load($(that).data("url") + ' ' + $(that).data("target")));
        $.getScript("js/slider/slider-animations.js");
        }, 1000);
        });
     }else{
        $("body").on("click", ".slide", function(e){
        e.preventDefault();
        $("#mission,#overview,#music,#potential,#people,#expression,#ethos,#cpd,#workshop,#team,#referrals,#local-links,#family,#mental,#palliative,#autism,#schools,#dementia,#private,#acreditations,#definitions,#research,#contact,#email,#phone,#contact-form,#finley,#councelling,#music-performance,#community-music,.slides").addClass("bounceOutUp");
        var that = this;
        setTimeout(function() {
       console.log($("#tam-content").load($(that).data("url") + ' ' + $(that).data("target")));
       $.getScript("js/slider/slider-animations.js");
        }, 1000);
        });
      }

这是运行浏览器特定代码的一个很好的小方法,你应该检查出来!