如何修复验证码中的错误包括addthis

时间:2021-09-15 23:07:33

I create captcha with javascript. here my code :

我用javascript创建验证码。我的代码:


    var a = Math.ceil(Math.random() * 10);
    var b = Math.ceil(Math.random() * 10);
    var c = Math.ceil(Math.random() * 10);       
    var d = a + b + c;
    function DrawBotBoot(){
        document.write("What is "+ a + " + " + b + " + " + c +" ? ");
    }    

    function ValidBotBoot(){
        var e = document.getElementById('BotBootInput').value;
        if (e == d) return true;        
        return false;
    }

    $(function() {
        $(".commentblogsubmit").click(function()
          {
          if(ValidBotBoot() == false){
            alert("Error");    
          }else{
            alert("Success !!!");
          }
        return false;
        });
    });

but if i included addthis, the alert allways error
sorry my english is bad

但如果我包括addthis,警告总是错误抱歉我的英语很糟糕

1 个解决方案

#1


0  

Your code probably conflicts with addthis. Probably a b c or d are used in addthis.

您的代码可能与addthis冲突。可能还有一个b c或d用于此。

The easy fix would be to just use variables with different, more descriptive, names. Another thing you could do is have the generation code inside the draw function and have it return the sum. So you say

简单的解决方法是使用具有不同,更具描述性的名称的变量。你可以做的另一件事是在draw函数中使用生成代码并让它返回总和。所以你说

var expected = DrawBotBoot();

Then you can pass in that value into the validate function for testing.

然后,您可以将该值传递给validate函数进行测试。

ValidBotBoot(expected)

This way the variables stay within the scope you want them to.

这样变量就会保持在你想要的范围内。

#1


0  

Your code probably conflicts with addthis. Probably a b c or d are used in addthis.

您的代码可能与addthis冲突。可能还有一个b c或d用于此。

The easy fix would be to just use variables with different, more descriptive, names. Another thing you could do is have the generation code inside the draw function and have it return the sum. So you say

简单的解决方法是使用具有不同,更具描述性的名称的变量。你可以做的另一件事是在draw函数中使用生成代码并让它返回总和。所以你说

var expected = DrawBotBoot();

Then you can pass in that value into the validate function for testing.

然后,您可以将该值传递给validate函数进行测试。

ValidBotBoot(expected)

This way the variables stay within the scope you want them to.

这样变量就会保持在你想要的范围内。