我有一个项目,我需要计算一个文本区域中拼写错误的单词的数量,如果有太多的拼写错误,则防止提交web表单。JavaScript编辑器tinyMCE用于条目表单。PHP脚本SpellCheckText.PHP计算拼写错误(如果有的话),并将JSON编码的结果返回给浏览器。下面的代码示例:
<html lang="en"> <head> <meta charset="UTF-8"> <title>Test</title> <link rel="stylesheet" src="/simages/css/bootstrap/3.3.7/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="/simages/scripts/js/tinymce/js/tinymce/tinymce.min.js"></script> <script> tinymce.init({ selector: ".standard-editor", plugins: "wordcount spellchecker", paste_as_text: false, theme: "modern", branding: false, content_style: ".mce-content-body {font-size:16px;font-family:Arial,sans-serif;}", browser_spellcheck: true, toolbar: "undo redo", spellchecker_rpc_url: '/simages/spellchecker/spellchecker.php', menubar: "tools", statusbar: true, height: "400", width: "600", paste_data_images: false, paste_enable_default_filters: false, paste_preprocess: function(plugin, args) { args.content = ''; } }); </script> <script type="text/javascript"> function checkWordCount() { var wordCount = tinyMCE.activeEditor.plugins["wordcount"].getCount(); if (wordCount < 50) { alert("Need 50 words or greater for your text submission..."); return false; } var essayContent = tinyMCE.activeEditor.getContent({format: 'text'}); function getSpellCount(essayContent){ return new Promise((resolve,reject) => { jQuery(function(\$) { var values = { 'str': essayContent }; \$.ajax({ type: "POST", url: "/path/to/spellcheckEssay.php", data: values, success: resolve, error: reject, }) }); }) } var percentage = getSpellCount(essayContent); percentage.then(function(result){ console.log(result); var grade = result.percentage; if(grade < 80){ alert("Please edit your response."); return false; }else{ document.essayform.submit(); } }).catch(function (error) { console.log('Failed',error); }); } </script> </head> <body> <div class="container-fluid"> <div class="form-group"> <form method=POST action="/path/to/ajax/textWords.php" name="essayform" id="essayQuestion" onsubmit="event.preventDefault();checkWordCount();"> <h3>$thesequestions{'Text'}</h3> <p> <textarea name="textarea" class="standard-editor" id="essay"></textarea> </p> <br/> <input class="btn btn-primary" type="submit" value="Submit Text"/> </form> </div> </div> </body> </html>``` I don't do front end coding that often, so don't know if the attempt to post twice in the same form is the problem or something else. Results of this example is a blank page where form's post action is executed. Don't believe that jQuery section is executed. Open to suggestions for a better method. Thank you. **Below is a revision of the original code post**: ```<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Test</title> <link rel="stylesheet" src="/css/bootstrap/3.3.7/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="/scripts/js/tinymce/js/tinymce/tinymce.min.js"></script> <script> tinymce.init({ selector: ".standard-editor", plugins: "wordcount spellchecker", paste_as_text: false, theme: "modern", branding: false, content_style: ".mce-content-body {font-size:16px;font-family:Arial,sans-serif;}", browser_spellcheck: true, toolbar: "undo redo", spellchecker_rpc_url: '/simages/spellchecker/spellchecker.php', menubar: "tools", statusbar: true, height: "400", width: "600", paste_data_images: false, paste_enable_default_filters: false, paste_preprocess: function(plugin, args) { args.content = ''; } }); </script> <script type="text/javascript"> function checkWordCount() { var wordCount = tinyMCE.activeEditor.plugins["wordcount"].getCount(); if (wordCount < 50) { alert("Need 50 words or greater for your text submission..."); return false; } var essayContent = tinyMCE.activeEditor.getContent({format: 'text'}); function getSpellCount(essayContent){ return new Promise((resolve,reject) => { jQuery(function($) { var values = { 'str': essayContent }; console.log(values); $.ajax({ type: "POST", url: "/path/to/ajax/spellcheckText.php", data: values, success: resolve, error: reject, }) }); }) } var percentage = getSpellCount(essayContent); percentage.then(function(result){ console.log(result); var grade = result.percentage; if(grade < 80){ alert("A number of misspelled words were detected. Please correct and submit again."); return false; } }).catch(function (error) { console.log('Failed',error); }); } </script> </head> <body> <div class="container-fluid"> <div class="form-group"> <form method=POST action="/path/to/ajax/textWords.php" name="essayform" id="essayQuestion" onsubmit="event.preventDefault();checkWordCount();"> <h3>$thesequestions{'Text'}</h3> <p> <textarea name="textarea" class="standard-editor" id="essay"></textarea> </p> <br/> <input class="btn btn-primary" type="submit" value="Submit Text"/> </form> </div> </div> </body> </html>```
以下是修订后的守则。Taplar指出了解决问题的路径,我错误地返回了false。此外,正确访问tinyMCE数据有助于使事情正常工作。
```<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test</title>
<link rel="stylesheet" src="/simages/css/bootstrap/3.3.7/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="/scripts/js/tinymce/js/tinymce/tinymce.min.js"></script>
<script>
tinymce.init({
selector: ".standard-editor",
plugins: "wordcount spellchecker",
paste_as_text: false,
theme: "modern",
branding: false,
content_style: ".mce-content-body {font-size:16px;font-family:Arial,sans-serif;}",
browser_spellcheck: true,
toolbar: "undo redo",
spellchecker_rpc_url: '/path/to/spellchecker/spellchecker.php',
menubar: "tools",
statusbar: true,
height: "400",
width: "600",
paste_data_images: false,
paste_enable_default_filters: false,
paste_preprocess: function(plugin, args) {
args.content = '';
}
});
</script>
<script type="text/javascript">
function checkWordCount() {
var wordCount = tinyMCE.activeEditor.plugins["wordcount"].getCount();
if (wordCount < 50) {
alert("Need 50 words or greater for your text submission...");
return false;
}
var essayContent = tinyMCE.activeEditor.getContent({format: 'text'});
function getSpellCount(essayContent){
return new Promise((resolve,reject) => {
jQuery(function($) {
var values = { 'str': essayContent };
console.log(values);
$.ajax({
type: "POST",
url: "/path/to/ajax/spellcheckText.php",
data: values,
success: resolve,
error: reject,
})
});
})
}
var percentage = getSpellCount(essayContent);
percentage.then(function(result){
console.log(result);
var grade = result.percentage;
if(grade < 80){
alert("A number of misspelled words were detected. Please correct and submit again.");
return false;
}
}).catch(function (error) {
console.log('Failed',error);
});
}
</script>
</head>
<body>
<div class="container-fluid">
<div class="form-group">
<form method=POST action="/path/to/ajax/textWords.php" name="essayform" id="essayQuestion" onsubmit="event.preventDefault();checkWordCount();">
<h3>$thesequestions{'text'}</h3>
<p>
<textarea name="textarea" class="standard-editor" id="essay"></textarea>
</p>
<br/>
<input class="btn btn-primary" type="submit" value="Submit Text"/>
</form>
</div>
</div>
</body>
</html>```
问题内容: 我有一个表,其中包含类似单词的列表: 所以我想如果有人写像 “ hela iam正在为gogle寻找类似引擎”。 现在,我想检查数据库中是否存在每个单词,如果不存在,应该使我得到与该单词相似的单词。例如:。好吧,我想修复拼写错误。在我的数据库中,我有所有英语单词的完整词典。我找不到任何对我有帮助的mysql函数。对我的情况没有帮助。 问题答案: 有一个功能确实可以满足您的要求,但是它很
问题内容: 我认为我已经很好地理解了这一点,但我认为该陈述是错误的。怎么说包含空格,加1。 编辑: 我发现(感谢Blender)可以用更少的代码来做到这一点: 问题答案: 使用方括号,而不是括号: 或: 您也可以使用:
拼写检查 1选择 “编辑 ”>“拼写检查 ”。 2若要设置用于单词的查找和忽略的选项,请单击对话框底部的箭头图标,并根据需要设置选项。 3单击 “开始 ”,即可开始进行拼写检查。 4当 Illustrator 显示出拼写错误的单词或其他可能的错误时,请执行下列操作之一: 单击 “忽略 ”或 “全部忽略 ”继续拼写检查,而不更改特定的单词。 从建议单词列表中选择一个单词,或在顶部的框中键入正确的单词
问题内容: 我有一个重复条目的单词。 我想计算并保存数据结构中每个单词的出现次数。 我该怎么做? 问题答案: 如果您没有大量的字符串,最短的实现方法是使用方法,如下所示: 输出:
我需要找到一个单词中元音的计数。然而,当我比较单词中的字母是否是元音时, 举个例子,我做的就像下面这个, ……)//其余部分被省略 语句变得太长。有没有办法将它们与正则表达式或类似正则表达式的比较进行比较,并给我字符串中元音出现的次数?
问题内容: 我正在寻找一种简单的方法来检查某个字符串是否是正确拼写的英语单词。例如,“ looked”将返回True,而“ hurrr”将返回False。我不需要拼写建议或任何拼写纠正功能。只是一个简单的函数,它需要一个字符串并返回一个布尔值。 问题答案: 两种可能的方法: 有自己的文件,其中包含所有有效的单词。将文件加载到集合中并比较每个单词以查看它是否存在(集合中的单词) (更好的方法)使用P