有人能告诉我为什么这段代码不起作用吗?我叮叮当当"检查拼写"没有任何结果。我以前做过这样的事情并且工作正常。如果您有更好的建议,我可以告诉我。
的index.php:
<!DOCTYPE html>
<head>
<title>Hi all</title>
<script type='text/javascript'>
var doAction = function() {
var text = document.getElementById("text").value;
var language = document.getElementById("language").value;
if(text != "") {
var xmlhttp;
if(window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
}
else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
var toSend = "text=" + text + "&language=" + language;
xmlhttp.open("POST", "checking.php", true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send(toSend);
document.getElementById("ratespelling").innerHTML = "send.";
xmlhttp.onreadystatechange = function() {
if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
if(xmlhttp.responseText != "") {
document.getElementById("ratespelling").innerHTML = "Your spelling is ?? accurate.";
document.getElementById("ctext").innerHTML = "Checked text: ".xmlhttp.responseText;
}
else {
document.getElementById("ctext").innerHTML = "Error.";
}
}
};
}
else {
document.getElementById("ctext").innerHTML = "Text not found.";
}
return false;
};
</script>
</head>
<body>
<form onSubmit="return doAction();" id="schecking" method="post">
<textarea name="text" rows=4 cols=40>Tekstas</textarea><br />
<select name="language" form="schecking">
<option value="en">English</option>
<option value="fr">France</option>
<option value="lt">Lithuanian</option>
<option value="pl">Polish</option>
</select>
<input type="submit" name="checking" value="Check spelling">
</form>
<div id="ratespelling"></div><br />
<div id="ctext"></div>
</html>
</body>
cheking.php
<?php
$text = explode(" ", $_POST['text']);
$language = $_POST['language'];
$pspell_link = pspell_new("en");
foreach($text as $word){
if (pspell_check($pspell_link, $word)){
echo $word;
}else{
echo "<span style="color:red">".$word."</span>";
}
}
?>
答案 0 :(得分:1)
我找到了一个:-)
改变这个:
<textarea name="text" rows=4 cols=40>Tekstas</textarea><br />
<select name="language" form="schecking">
到此:
<textarea id="text" name="text" rows=4 cols=40>Tekstas</textarea><br />
<select id="language" name="language" form="schecking">
答案 1 :(得分:0)
您在这里传递ID值。
var text = document.getElementById("text").value;
var language = document.getElementById("language").value;
在表单中编辑,然后检查
<textarea name="text" id="text" rows=4 cols=40>Tekstas</textarea><br />
<select name="language" id="language" form="schecking">