简体   繁体   English

jquery在单击事件上添加类不起作用

[英]jquery add class on click event not working

in my project have menu and i give them ids for sub menu and it's in header.php在我的项目中有菜单,我为它们提供了子菜单的 id,它在 header.php 中

<div class="top-menu">
    <ul>
    <nav class="cl-effect-13">
    <li><a href="about.php" id="about">About</a></li>
    <li><a href="product.php" id="product">Products</a></li>
    <li><a class="scroll" href="#news" id="news">News</a></li>
    <li><a href="typography.php" id="typo">Typo</a></li>
    <li><a href="contact.php" id="contact">Contact</a></li>
    </nav>
    </ul>
</div>

now when i click about it goes to about.php or if i click contact it goes to contact.php.现在,当我点击关于它去about.php 或者如果我点击联系它去contact.php。 now in about.php i insert jquery like this.现在在about.php中,我像这样插入jquery。

<script type="text/javascript">
    $(document).ready(function() {
            /*
            var defaults = {
            containerID: 'toTop', // fading element id
            containerHoverID: 'toTopHover', // fading element hover id
            scrollSpeed: 1200,
            easingType: 'linear' 
            };
            */
    $().UItoTop({ easingType: 'easeOutQuart' });
    $('#about').addClass('active');
});
</script>

and for different php file i give diff.对于不同的 php 文件,我给出了差异。 id. ID。 it's working fine till i insert following code in footer.php它工作正常,直到我在 footer.php 中插入以下代码

<script src="https://code.jquery.com/jquery-2.1.1.min.js" type="text/javascript"></script>
            <script>
            function sendContactus() {
                var valid;  
                valid = validateContactto();
                if(valid) {
                    jQuery.ajax({
                    url: "dropusline.php",
                    data:'fname='+$("#fname").val()+'&lname='+$("#lname").val()+'&email='+$("#email").val()+'&phone='+$("#phone").val()+'&message='+$("#message").val(),
                    type: "POST",
                    success:function(data){
                    $("#mail-statusto").html(data);
                    },
                    error:function (){}
                    });
                }
            }

            function validateContactto() {
                var valid = true;   
                $(".text").css('background-color','');
                $(".error").html('');

                if(!$("#email").val()) {
                    $("#email-info").html("(required)");
                    $("#email").css('background-color','#FFFFDF');
                    valid = false;
                }
                if(!$("#message").val()) {
                    $("#message-info").html("(required)");
                    $("#message").css('background-color','#FFFFDF');
                    valid = false;
                }   
                return valid;
            }
            </script>

it's ajax code for inquiry in footer part and i include footer.php for all files that mention in header.php.它是用于页脚部分查询的 ajax 代码,我将 footer.php 包含在 header.php 中提到的所有文件中。 i want javascript code that in footer.php as well as jquery code to perform.我想要在footer.php 中的javascript 代码以及jquery 代码来执行。 now jquery code is not performing.现在 jquery 代码没有执行。

It doesn't look like you have the easing and ui totop scripts.看起来您没有 easing 和 ui totop 脚本。 Include them before invoking the plugin.在调用插件之前包含它们。

In this order:按照这个顺序:

<script src="http://lab.mattvarone.com/projects/jquery/totop/js/jquery-1.7.2.min.js"></script>
<script src="http://lab.mattvarone.com/projects/jquery/totop/js/easing.js"></script>
<script src="http://lab.mattvarone.com/projects/jquery/totop/js/jquery.ui.totop.js"></script>

<script>
 $().UItoTop({easingType: 'easeOutQuart'});
</script>

it's done by removing this line in footer.php这是通过删除footer.php中的这一行来完成的

<script src="https://code.jquery.com/jquery-2.1.1.min.js" type="text/javascript"></script>

it's reflecting because i already included in header.php like this.它的反映是因为我已经像这样包含在 header.php 中。

<script src="js/jquery.min.js"></script>

any one can explain me why not to call it twice?任何人都可以解释我为什么不叫它两次?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM