Javascript标记问题

Javascript markers issue

本文关键字:问题 Javascript      更新时间:2023-09-26

在我的页面上,我有引导猫头鹰轮播和联系表格。问题是联系表单正常工作或轮播滑块滑动图片 - 两者兼而有之。我发现了问题所在,但不知道如何解决。下面找到我的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中还有一些标记错别字,你能看看吗?

进一步讨论:如果我将轮播 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>

尝试以下代码:

$(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>

尝试删除 json 中的注释:

$(document).ready(function() {

var owl = $("#owl-hero");
owl.owlCarousel({
    navigation: false,
    slideSpeed: 1,
    paginationSpeed: 400,
    singleItem: true,
    transitionStyle: "fade"
});
});

它在语法上不正确。