在将Chrome浏览器添加到主网站后,JQuery代码在Google Chrome中无法使用 [英] JQuery code not working in Google Chrome after adding it to main website

查看:217
本文介绍了在将Chrome浏览器添加到主网站后,JQuery代码在Google Chrome中无法使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的JQuery代码不工作在谷歌浏览器,当我在主要网站上测试,但它的工作在IE。此外,当我使用谷歌浏览器在JSFiddle测试它,它的工作。这是我的完整代码: http://jsfiddle.net/xV3x8/3/

My JQuery code is not working in Google Chrome when I am testing it on main website but its working in IE. Also when I am testing it in JSFiddle using Google Chrome, it's working there. Here is my complete code: http://jsfiddle.net/xV3x8/3/

您可以检查我的这个问题:如果您想知道此代码的动机是什么,则无法覆盖点击事件,从用户创建的函数锚定代码。

You can check my this question: Unable to override click events to anchor tag from a user created function if you want to know what is the motive of this code.

JQuery代码:

var $defaultDiv =  "<a class='p-small bg-green' id='up' href='#'>Up</a>" 
                 + "<a class='p-small bg-red' id='down' href='#'>Down</a>",
    $animatedDiv = "<div id='aniDiv' class='base {{bg}}'></div>"
                +  "<div class='overlay'>"
+  "<a class='black' id='unvote' href='#'>You {{vote}}. Click to take vote back.</a></div>";

$('#Vote').on('click', '#up', function() {
    animateDiv("bg-green", true);
});

$('#Vote').on('click', '#down', function() {
    animateDiv("bg-red", false);
});

$('#Vote').on('click', '#unvote', function() {
    $('#Vote').html($defaultDiv);
});

function animateDiv(bgColor, upVoted) {
    $('#Vote').html($animatedDiv.replace("{{bg}}", bgColor)
                    .replace("{{vote}}", upVoted ? "upvoted" : "downvoted"));
    $("#aniDiv").animate({
        width: "10px"
    });
    $("#Vote").width("350px");
}


推荐答案

所有我需要做的是从我的链接中删除 href ='#'。我不知道为什么这不工作在Chrome。如果有人能解释我,这将是一个很大的帮助。 href ='#'我想通常添加到激活链接使用JavaScript函数的锚点击,但可以使用CSS cursor:pointer

Finally I found the solution. All I need to do is to remove href='#' from my links. I don't know why this is not working in Chrome. If anybody can explain me it will be a great help. href='#' I think usually added to activate links for anchors that use JavaScript function on click, but that can be done using CSS cursor: pointer.

这篇关于在将Chrome浏览器添加到主网站后,JQuery代码在Google Chrome中无法使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆