Javascript 如何检查文本是否与要求的文本几乎相同

Javascript 如何检查文本是否与要求的文本几乎相同,javascript,jquery,html,Javascript,Jquery,Html,我想检查我的textarea的值是否与要求的值几乎相同,例如: 我有一个HTML代码: <textarea class="ab" placeholder="Type here"></textarea> <div class="result"> </div> 这段代码不是我想要的,实际上,这正是我试图做的。但我想要的是,例如,当$('.ab')的值几乎与文本相同时,关于开源软件,以下哪项通常是正确的?就像一样,对于开源软件,$(“.result”)

我想检查我的textarea的值是否与要求的值几乎相同,例如:

我有一个HTML代码:

<textarea class="ab" placeholder="Type here"></textarea>
<div class="result">
</div>
这段代码不是我想要的,实际上,这正是我试图做的。但我想要的是,例如,当
$('.ab')
的值几乎与文本
相同时,关于开源软件,以下哪项通常是正确的?
就像
一样,对于开源软件,
$(“.result”)通常是正确的
仍然保留html,因为它通常是在志愿者的基础上开发的,任何人都可以自由更改它(正确)。


那么我该怎么做呢,感谢您的帮助

尝试将输入文本拆分成数组,使用
$。each()
迭代输入单词,如果输入单词与所选短语中至少五个单词匹配,则返回true,否则在
if
处返回false;例如。;尝试在
textarea

以下关于开源的内容通常是正确的
正确的

$(文档).ready(函数(){
$(“.btn”)。单击(函数(){
var a=$(“.ab”);
var b=$(“.result”);
var arr=a.val().split(/\s+/);
var n=0;
var phrase=“关于开源软件,以下哪项通常是正确的?”;
$。每个(arr、功能(键、值){
如果(短语索引f(val)>=0)++n;
})
如果(n>=5){
b、 html(“它通常是在自愿的基础上开发的,任何人都可以自由更改它(正确)。”;
}
否则{
b、 html(“错误”);
};
a、 val(“”);n=0;
});
});

单击
实际上应该是:

    $(document).ready(function(){
        $(".btn").click(function(){
            var a = $(".ab").val();
            var b = $(".result").html();
            var c = 'Which of the following is generally true about Open Source software?';
            console.log(c.indexOf(a));
            if(c.indexOf(a) >= 0){
                $('.result').html('Its usually developed on a volunteer basis and anyone is free to change it (correct).');
            } else {
                $(".result").html("error");
            }
        });

    }); 

<textarea class="ab" placeholder="Type here">following is generally true about Open Source</textarea>
<div class="result"></div>
<button class="btn">test</button>
$(文档).ready(函数(){
$(“.btn”)。单击(函数(){
var a=$(“.ab”).val();
var b=$(“.result”).html();
var c='关于开源软件,以下哪项通常是正确的?';
console.log(c.indexOf(a));
如果(c.indexOf(a)>=0){
$('.result').html('它通常是在志愿者的基础上开发的,任何人都可以自由更改它(正确)。';
}否则{
$(“.result”).html(“错误”);
}
});
}); 
以下是关于开源的基本情况
测试

没有简单的解决方案,请对模糊搜索进行一些研究。如果十个输入单词中有五个匹配字符串,那么这个问题就太广泛了,没有更精确的搜索标准是必需的。当我使用字符串进行测试时,它对我不起作用:“以下哪一个通常是”,它不会返回结果“它通常是在自愿的基础上开发的,任何人都可以自由更改它(正确)。”它返回“它通常是在志愿者的基础上开发的,任何人都可以自由更改它(正确)。”对我来说。好吧,谢谢,但它实际上不适用于字符串“following is generally true”。@user3722325“following is generally true”是四个单词,用“following is generally true”来尝试?或者,如果
条件为
n>=4
,则调整
。注意,增加匹配计数时,不检查前一个单词是否为当前单词;i、 例如,“true”可能返回
true
;尽管这一部分可以调整以测试不同类型的匹配words@user3722325另见
    $(document).ready(function(){
        $(".btn").click(function(){
            var a = $(".ab").val();
            var b = $(".result").html();
            var c = 'Which of the following is generally true about Open Source software?';
            console.log(c.indexOf(a));
            if(c.indexOf(a) >= 0){
                $('.result').html('Its usually developed on a volunteer basis and anyone is free to change it (correct).');
            } else {
                $(".result").html("error");
            }
        });

    }); 

<textarea class="ab" placeholder="Type here">following is generally true about Open Source</textarea>
<div class="result"></div>
<button class="btn">test</button>