⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 25.4.htm

📁 这是我卖的书上的源码 这书是电子邮电出版的是有关网络编程 有详细的例子
💻 HTM
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>RPC Spellchecker</title>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<script type="text/javascript">
<!--
var commandURL = "http://demos.javascriptref.com/checkspelling.php?";
var rpcComplete = false;
var rpcResult = null;
var timer = null;
// 发送URL中给出的RPC。服务器会返回JavaScript,其中,设置rpcComplete 为 true,
// 设置rpcResult 为true (表示单词拼写正确),或者是一个字符串 (包含正确的拼写)。
function sendRPC(url) 
{
// 如果某个RPC被挂起,则等待其完成
if (timer) 
{
setTimeout("sendRPC('" + url + "')", 71);  // 在71毫秒内重试
return;
}
rpcComplete = false;
//以下设置script一些选项
var newScript = document.createElement('script');
newScript.src = url;
newScript.type = "text/javascript";
document.body.appendChild(newScript);
readResponse();
}
function checkSpelling(word) //函数:检查拼写
{
var params = "word=" + word;
sendRPC(commandURL + params); //调用sendRPC()函数
}
function readResponse() 
{
if (!rpcComplete)   //如果RPC未完成
{
timer = setTimeout(readResponse, 50); //设置计时器
return; //返回
}
// RPC 完整,因此检测内容
if (rpcResult === true)
alert("单词拼写正确。");
else
alert("单词拼写错误,正确的拼写可能是: " +rpcResult);
timer = rpcResult = null; //计时器置空
}
//-->
</script>
</head>
<body>
<h2>服务端拼写检查</h2>
<form name="spellform" id="spellform" action="#" method="get">
Check the spelling of
<input type="text" name="word" id="word" value="absquatalate">
<!--通过onclick调用onclick="checkSpelling()函数,参数为文本框内容-->
<input type="button" value="检测" 
onclick="checkSpelling(document.spellform.word.value);">
</form>
如果输入“the”,服务端 CGI 脚本会返回:<br>
rpcComplete = true;<br>
rpcResult = true;<p>
如果输入了一个拼错的单词,比如输入“absquatalate”,服务器会返回正确的拼写:<br>
rpcComplete = true;<br>
rpcResult = "absquatulate";
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -