【问题标题】:Javascript markers issueJavascript标记问题
【发布时间】:2016-06-06 16:14:06
【问题描述】:

在我的页面上,我有引导猫头鹰轮播和联系表格。问题是联系表格正在工作或轮播滑块滑动图片 - 两者之一。我发现问题出在哪里,但不知道如何解决。下面找到我的 JS 代码。第一个是猫头鹰轮播,剩下两个是我的联系表格。

<script>

$(document).ready(function() {

    var owl = $("#owl-hero");

    owl.owlCarousel({

        navigation: false, // Show next and prev buttons
        slideSpeed: 1,
        paginationSpeed: 400,
        singleItem: true,
        transitionStyle: "fade"

    });
    });

$(document).ready(function() {
    $("#contactForm").on("submit", function(event) {
        if (event.isDefaultPrevented()) {
        } else {
            event.preventDefault();
            submitForm();
        }
    });

});

function submitForm() {
    $.ajax({
        type: "POST",
        url: "mail.php",
        data: $("#contactForm").serialize(),
        success: function(text) {
            if (text == "success") {
                $("#msgSubmit" ).removeClass( "hidden" );
                setTimeout(function() {
                    $("#msgSubmit" ).addClass( "hidden");    
                }, 6000);
            }
        },
        error : function() {
            /* You probably want to add an error message as well */
            $("#msgError" ).removeClass( "hidden" );
        }
    });
};

</script>

当我按上述方式使用时 - 我的联系表正在工作,我的意思是我发送邮件并向用户显示消息 - 但我的轮播没有滑动图片 - 它是堆栈。

如果我想要我的旋转木马作品,我必须在末尾剪下标记,如下所示:

$(document).ready(function() {

    var owl = $("#owl-hero");

    owl.owlCarousel({

        navigation: false, // Show next and prev buttons
        slideSpeed: 1,
        paginationSpeed: 400,
        singleItem: true,
        transitionStyle: "fade"

    });

这个是从头剪掉的:

});

现在轮播有效,但联系表格无效。我相信我的 JS 中还有一些标记错字,你能看一下吗?

进一步讨论: 如果我将 carousel JS 拆分为单独的括号 - 但没有正确封闭的标记 - 那么一切似乎都在工作.. ;/见下文:

<script>

$(document).ready(function() {

    var owl = $("#owl-hero");

    owl.owlCarousel({

        navigation: false, // Show next and prev buttons
        slideSpeed: 1,
        paginationSpeed: 400,
        singleItem: true,
        transitionStyle: "fade"

    });
    }
</script>

    <script>
$(document).ready(function() {
    $("#contactForm").on("submit", function(event) {
        if (event.isDefaultPrevented()) {
        } else {
            event.preventDefault();
            submitForm();
        }
    });

});

function submitForm() {
    $.ajax({
        type: "POST",
        url: "mail.php",
        data: $("#contactForm").serialize(),
        success: function(text) {
            if (text == "success") {
                $("#msgSubmit" ).removeClass( "hidden" );
                setTimeout(function() {
                    $("#msgSubmit" ).addClass( "hidden");    
                }, 6000);
            }
        },
        error : function() {
            /* You probably want to add an error message as well */
            $("#msgError" ).removeClass( "hidden" );
        }
    });
};

</script>

【问题讨论】:

  • 浏览器控制台有没有遇到JS错误?
  • 使其工作的唯一方法是将轮播 JS 脚本分隔在其自己的
  • 答案已添加,请尝试看看是否有效。
  • 有人知道吗?

标签: javascript php html twitter-bootstrap


【解决方案1】:

试试下面的代码:

$(document).ready(function() {

    var owl = $("#owl-hero");

    owl.owlCarousel({

        navigation: false, // Show next and prev buttons
        slideSpeed: 1,
        paginationSpeed: 400,
        singleItem: true,
        transitionStyle: "fade"

    });

    $("#contactForm").on("submit", function(event) {
        if (event.isDefaultPrevented()) {
        } else {
            event.preventDefault();
            submitForm();
        }
    });

});

function submitForm() {
    $.ajax({
        type: "POST",
        url: "mail.php",
        data: $("#contactForm").serialize(),
        success: function(text) {
            if (text == "success") {
                $("#msgSubmit" ).removeClass( "hidden" );
                setTimeout(function() {
                    $("#msgSubmit" ).addClass( "hidden");    
                }, 6000);
            }
        },
        error : function() {
            /* You probably want to add an error message as well */
            $("#msgError" ).removeClass( "hidden" );
        }
    });
}
</script>

【讨论】:

  • 旋转木马不工作 - 我的意思是没有滑动......它在第一张图片上的堆栈
【解决方案2】:

尝试去掉json里面的注释:

$(document).ready(function() {

var owl = $("#owl-hero");

owl.owlCarousel({

    navigation: false,
    slideSpeed: 1,
    paginationSpeed: 400,
    singleItem: true,
    transitionStyle: "fade"

});
});

语法不正确。

【讨论】:

  • 做了但还是一样。
  • 你用的是什么浏览器? Firefox + Firebug 在出现错误时更可靠。 Chrome 有时会在不说明原因的情况下失败。
  • 我使用的是 chrome、firefox,即 edge。我到底能做些什么来举报和调查呢?
猜你喜欢
  • 2022-11-26
  • 1970-01-01
  • 1970-01-01
  • 2012-03-28
  • 2020-04-28
  • 2023-03-08
  • 2014-08-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多