小巧适用的AJAX英汉汉英字典

简介: 俺们程序员在工作中常常会查查字典,找一下英文单词怎么拼的或者看看单词的意思。这个时候我们必然要使用一些字典软件,如金山词霸之类,或者去一些查单词的网站,到达查询页面后,输入单词,等待刷新之后才能获得查询的结果。

俺们程序员在工作中常常会查查字典,找一下英文单词怎么拼的或者看看单词的意思。这个时候我们必然要使用一些字典软件,如金山词霸之类,或者去一些查单词的网站,到达查询页面后,输入单词,等待刷新之后才能获得查询的结果。

这里送给大家一款AJAX的英汉汉英字典,体积小、纯HTML打造、无需安装、反应速度快、方便快捷、功能强大,是居家旅行、杀人放火之必备良药。那么,请问这么好的字典,哪里有买的呢?且看:

img_a6339ee3e57d1d52bc7d02b338e15a60.gif < html >
img_a6339ee3e57d1d52bc7d02b338e15a60.gif
< meta  http-equiv =Content-Type  content ="text/html;charset=gb2312" >
img_a6339ee3e57d1d52bc7d02b338e15a60.gif
< head >
img_a6339ee3e57d1d52bc7d02b338e15a60.gif    
< link  href ="http://www.dict.cn/img/search.css"  rel ="stylesheet"  type ="text/css" >
img_a6339ee3e57d1d52bc7d02b338e15a60.gif    
< script  src ='http://www.dict.cn/img/search.js'  language ='javascript' ></ script >
img_a6339ee3e57d1d52bc7d02b338e15a60.gif
img_405b18b4b6584ae338e0f6ecaf736533.gifimg_1c53668bcee393edac0d7b3b3daff1ae.gif    
< script  language ="javascript" > img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif
img_33d02437d135341f0800e3d415312ae8.gif 
img_33d02437d135341f0800e3d415312ae8.gif     window.onload 
= function()
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif     
img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif
img_105a1e124122b2abcee4ea8e9f5108f3.gif     }

img_33d02437d135341f0800e3d415312ae8.gif
img_33d02437d135341f0800e3d415312ae8.gif     
var xmlHttp = false;
img_33d02437d135341f0800e3d415312ae8.gif     
var e;
img_33d02437d135341f0800e3d415312ae8.gif     
img_33d02437d135341f0800e3d415312ae8.gif     
//创建XMLHTTP对象
img_33d02437d135341f0800e3d415312ae8.gif
     function getXMLHTTPObj()
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif     
img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif        
var C = null;
img_33d02437d135341f0800e3d415312ae8.gif        
try
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif            C 
= new ActiveXObject("Msxml2.XMLHTTP");
img_105a1e124122b2abcee4ea8e9f5108f3.gif        }

img_33d02437d135341f0800e3d415312ae8.gif        
catch(e)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif            
try
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif            
img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif                C 
= new ActiveXObject("Microsoft.XMLHTTP");
img_105a1e124122b2abcee4ea8e9f5108f3.gif            }

img_33d02437d135341f0800e3d415312ae8.gif            
catch(sc)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif            
img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif                C 
= null;
img_105a1e124122b2abcee4ea8e9f5108f3.gif            }

img_105a1e124122b2abcee4ea8e9f5108f3.gif        }

img_33d02437d135341f0800e3d415312ae8.gif        
img_33d02437d135341f0800e3d415312ae8.gif        
if!&& typeof XMLHttpRequest != "undefined" )
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif            C 
= new XMLHttpRequest();
img_105a1e124122b2abcee4ea8e9f5108f3.gif        }

img_33d02437d135341f0800e3d415312ae8.gif        
img_33d02437d135341f0800e3d415312ae8.gif        
return C;
img_105a1e124122b2abcee4ea8e9f5108f3.gif     }

img_33d02437d135341f0800e3d415312ae8.gif     
img_33d02437d135341f0800e3d415312ae8.gif     
//调用远程方法
img_33d02437d135341f0800e3d415312ae8.gif
     function callServer(e) 
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif     
img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif
img_33d02437d135341f0800e3d415312ae8.gif        document.getElementById(
"lookup_result").style.display = "none";
img_33d02437d135341f0800e3d415312ae8.gif        
//获取查询日期
img_33d02437d135341f0800e3d415312ae8.gif
        var lookup_obj = document.getElementById("word");
img_33d02437d135341f0800e3d415312ae8.gif        
var lookup_word = lookup_obj.value;
img_33d02437d135341f0800e3d415312ae8.gif        
img_33d02437d135341f0800e3d415312ae8.gif        LookUp(lookup_word);
img_105a1e124122b2abcee4ea8e9f5108f3.gif     }

img_33d02437d135341f0800e3d415312ae8.gif     
img_33d02437d135341f0800e3d415312ae8.gif     
//查字典
img_33d02437d135341f0800e3d415312ae8.gif
     function LookUp(sIn) 
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif     
img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif
img_33d02437d135341f0800e3d415312ae8.gif        
var lookup_obj = document.getElementById("word");
img_33d02437d135341f0800e3d415312ae8.gif
img_33d02437d135341f0800e3d415312ae8.gif        lookup_obj.value 
= sIn.split("&")[0];
img_33d02437d135341f0800e3d415312ae8.gif        
img_33d02437d135341f0800e3d415312ae8.gif        
try
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif            
if( xmlHttp && ( xmlHttp.readyState != 0 ) )
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif            
img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif                xmlHttp.abort();
img_105a1e124122b2abcee4ea8e9f5108f3.gif            }

img_33d02437d135341f0800e3d415312ae8.gif    
img_33d02437d135341f0800e3d415312ae8.gif            xmlHttp 
= getXMLHTTPObj();
img_33d02437d135341f0800e3d415312ae8.gif    
img_33d02437d135341f0800e3d415312ae8.gif            
if( xmlHttp )
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif            
img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif                
//构造查询连接字符串
img_33d02437d135341f0800e3d415312ae8.gif
                var url = "http://www.dict.cn/search/?q=" + sIn;
img_33d02437d135341f0800e3d415312ae8.gif                
//打开连接
img_33d02437d135341f0800e3d415312ae8.gif
                xmlHttp.open("GET", url, true);
img_33d02437d135341f0800e3d415312ae8.gif                
//设置回调函数
img_33d02437d135341f0800e3d415312ae8.gif
                xmlHttp.onreadystatechange = updatePage;
img_33d02437d135341f0800e3d415312ae8.gif                
//发送请求
img_33d02437d135341f0800e3d415312ae8.gif
                xmlHttp.send(null);
img_105a1e124122b2abcee4ea8e9f5108f3.gif            }

img_33d02437d135341f0800e3d415312ae8.gif            
else
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif            
img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif                document.getElementById(
"flag").innerHTML = "XMLHTTP对象创建失败";
img_105a1e124122b2abcee4ea8e9f5108f3.gif            }

img_105a1e124122b2abcee4ea8e9f5108f3.gif        }

img_33d02437d135341f0800e3d415312ae8.gif        
catch (e)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif            document.getElementById(
"flag").innerHTML = "查询错误:" + e;
img_105a1e124122b2abcee4ea8e9f5108f3.gif        }

img_105a1e124122b2abcee4ea8e9f5108f3.gif     }

img_33d02437d135341f0800e3d415312ae8.gif     
img_33d02437d135341f0800e3d415312ae8.gif     
//回调处理函数
img_33d02437d135341f0800e3d415312ae8.gif
     function updatePage() 
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif     
img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif        
try
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif            
if (xmlHttp.readyState == 1
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif            
img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif            
//        document.getElementById("flag").innerHTML = "正在加载连接对象img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gifimg_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif";
img_105a1e124122b2abcee4ea8e9f5108f3.gif
            }

img_33d02437d135341f0800e3d415312ae8.gif            
img_33d02437d135341f0800e3d415312ae8.gif            
if (xmlHttp.readyState == 2
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif            
img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif            
//        document.getElementById("flag").innerHTML = "连接对象加载完毕。";
img_105a1e124122b2abcee4ea8e9f5108f3.gif
            }

img_33d02437d135341f0800e3d415312ae8.gif            
img_33d02437d135341f0800e3d415312ae8.gif            
if (xmlHttp.readyState == 3
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif            
img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif            
//        document.getElementById("flag").innerHTML = "数据获取中img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gifimg_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif";
img_105a1e124122b2abcee4ea8e9f5108f3.gif
            }

img_33d02437d135341f0800e3d415312ae8.gif            
img_33d02437d135341f0800e3d415312ae8.gif            
if (xmlHttp.readyState == 4
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif            
img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif            
//            document.getElementById("flag").innerHTML = "数据获取成功";
img_33d02437d135341f0800e3d415312ae8.gif
            
img_33d02437d135341f0800e3d415312ae8.gif                
var response = bytes2BSTR(xmlHttp.responseBody) ;
img_33d02437d135341f0800e3d415312ae8.gif                
var OpenValue = response.split("<big><b>")[1];
img_33d02437d135341f0800e3d415312ae8.gif                
var OpenValue = OpenValue.split("<td align=\"right\">")[0];
img_33d02437d135341f0800e3d415312ae8.gif                
var OpenValue = ReplaceAll(OpenValue,"/img/","http://www.dict.cn/img/");
img_33d02437d135341f0800e3d415312ae8.gif                
img_33d02437d135341f0800e3d415312ae8.gif                
//替换 近似解释 的查询链
img_33d02437d135341f0800e3d415312ae8.gif
                var OpenValue = ReplaceAll(OpenValue,"href=./?q=","href=javascript:LookUp(\"");
img_33d02437d135341f0800e3d415312ae8.gif                var OpenValue = ReplaceAll(OpenValue,
">&lt;<font color=#223322","\")>&lt;<font color=#223322");
img_33d02437d135341f0800e3d415312ae8.gif                
img_33d02437d135341f0800e3d415312ae8.gif                
//替换 同义词 的查询链接
img_33d02437d135341f0800e3d415312ae8.gif
                var restr = /<a href="index.php\?q=(.*?)">(.*?)<\/a>/g;
img_33d02437d135341f0800e3d415312ae8.gif                
var newstr = "<a href=\"javascript:LookUp('$1')\">$2</a>";
img_33d02437d135341f0800e3d415312ae8.gif                
var OpenValue = OpenValue.replace(restr,newstr);
img_33d02437d135341f0800e3d415312ae8.gif                
img_33d02437d135341f0800e3d415312ae8.gif                
//屏蔽 添加到单词本
img_33d02437d135341f0800e3d415312ae8.gif
                var OpenValue = ReplaceAll(OpenValue,"src=http://www.dict.cn/img/wordbook.gif","src=/img/wordbook.gif width=0");
img_33d02437d135341f0800e3d415312ae8.gif                
var OpenValue = ReplaceAll(OpenValue,"加入生词本","");
img_33d02437d135341f0800e3d415312ae8.gif                
img_33d02437d135341f0800e3d415312ae8.gif                document.getElementById(
"flag").innerHTML = OpenValue;
img_105a1e124122b2abcee4ea8e9f5108f3.gif            }

img_105a1e124122b2abcee4ea8e9f5108f3.gif        }

img_33d02437d135341f0800e3d415312ae8.gif        
catch (e) 
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif          document.getElementById(
"flag").innerHTML = "回调处理错误:" + e;
img_105a1e124122b2abcee4ea8e9f5108f3.gif        }

img_105a1e124122b2abcee4ea8e9f5108f3.gif     }

img_33d02437d135341f0800e3d415312ae8.gif 
img_33d02437d135341f0800e3d415312ae8.gif    
function enterToTab()
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif    
img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif        
if(event.keyCode == 13)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif            event.keyCode 
= 9;
img_105a1e124122b2abcee4ea8e9f5108f3.gif        }

img_105a1e124122b2abcee4ea8e9f5108f3.gif    }

img_05dd8d549cff04457a6366b0a7c9352a.gif    
</ script >
img_405b18b4b6584ae338e0f6ecaf736533.gifimg_1c53668bcee393edac0d7b3b3daff1ae.gif    
< script  type ="text/vbscript"  language ="vbscript" > img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif
img_33d02437d135341f0800e3d415312ae8.gif    Function ReplaceAll(sIn,sFind,sReplace)
img_33d02437d135341f0800e3d415312ae8.gif        strReturn 
= ""
img_33d02437d135341f0800e3d415312ae8.gif        strReturn 
= Replace(sIn,sFind,sReplace)
img_33d02437d135341f0800e3d415312ae8.gif        ReplaceAll 
= strReturn
img_33d02437d135341f0800e3d415312ae8.gif    End Function 
img_33d02437d135341f0800e3d415312ae8.gif
img_33d02437d135341f0800e3d415312ae8.gif    Function bytes2BSTR(vIn)
img_33d02437d135341f0800e3d415312ae8.gif        strReturn 
= ""
img_33d02437d135341f0800e3d415312ae8.gif        For i 
= 1 To LenB(vIn)
img_33d02437d135341f0800e3d415312ae8.gif            ThisCharCode 
= AscB(MidB(vIn,i,1))
img_33d02437d135341f0800e3d415312ae8.gif            If ThisCharCode 
< &H80 Then
img_33d02437d135341f0800e3d415312ae8.gif                strReturn 
= strReturn & Chr(ThisCharCode)
img_33d02437d135341f0800e3d415312ae8.gif            Else
img_33d02437d135341f0800e3d415312ae8.gif                NextCharCode 
= AscB(MidB(vIn,i+1,1))
img_33d02437d135341f0800e3d415312ae8.gif                strReturn 
= strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
img_33d02437d135341f0800e3d415312ae8.gif                i 
= i + 1
img_33d02437d135341f0800e3d415312ae8.gif            End If
img_33d02437d135341f0800e3d415312ae8.gif        Next
img_33d02437d135341f0800e3d415312ae8.gif        bytes2BSTR 
= strReturn
img_33d02437d135341f0800e3d415312ae8.gif    End Function 
img_05dd8d549cff04457a6366b0a7c9352a.gif    
</ script >
img_a6339ee3e57d1d52bc7d02b338e15a60.gif
</ head >
img_a6339ee3e57d1d52bc7d02b338e15a60.gif
< body >
img_a6339ee3e57d1d52bc7d02b338e15a60.gif    
< form >
img_a6339ee3e57d1d52bc7d02b338e15a60.gif        
< span  class ="f pl30" > 请输入要查询的汉字或者英文: </ span >< br />
img_a6339ee3e57d1d52bc7d02b338e15a60.gif        
< input  type ="text"  id ="word"  onblur ="callServer(this);"  onkeydown ="enterToTab();"  onmouseover ="this.focus()"  onfocus ="this.select()"  value ="english"  accesskey ="c"   />
img_a6339ee3e57d1d52bc7d02b338e15a60.gif        
< div  id ="lookup_result" >
img_a6339ee3e57d1d52bc7d02b338e15a60.gif        
</ div >
img_a6339ee3e57d1d52bc7d02b338e15a60.gif        
< div  id ="flag" >
img_a6339ee3e57d1d52bc7d02b338e15a60.gif        
</ div >
img_a6339ee3e57d1d52bc7d02b338e15a60.gif    
</ form >
img_a6339ee3e57d1d52bc7d02b338e15a60.gif
</ body >
img_a6339ee3e57d1d52bc7d02b338e15a60.gif
</ html >
img_a6339ee3e57d1d52bc7d02b338e15a60.gif

拷贝以上代码,另存为一个html的文件,字典便有了。
界面相当的简单,只有一个输入框,填入你想要查询的单词,Tab或者回车一下,单词解释会立马显示出来。汉语的词有相近单词;英语的话有近似词,均可直接点击查询哦。

最后再次感谢一下我们的字典数据来源: www.dict.cn ,网站的确做的不错,是个学英语的好去处。
目录
相关文章
|
XML 前端开发 JavaScript
什么是Ajax和jquery
什么是Ajax和jquery
89 0
|
7月前
|
JSON 前端开发 Java
利用Spring Boot处理JSON数据实战(包括jQuery,html,ajax)附源码 超详细
利用Spring Boot处理JSON数据实战(包括jQuery,html,ajax)附源码 超详细
161 0
|
7月前
|
敏捷开发 JavaScript 前端开发
❤❤❤【Vue.js最新版】sd.js基于jQuery Ajax最新原生完整版for凯哥API版本❤❤❤
❤❤❤【Vue.js最新版】sd.js基于jQuery Ajax最新原生完整版for凯哥API版本❤❤❤
|
前端开发 JavaScript
jQuery中的Ajax请求----ajax请求篇(二)
在jQuery中的Ajax请求其实是在底层对原生js请求方式的封装,那么jQuery中的Ajax请求是怎样的呢?
68 0
|
7月前
|
前端开发 JavaScript
Jquery ajax捕获错误信息
Jquery ajax捕获错误信息
63 0
|
7月前
|
JSON 缓存 前端开发
Jquery中AJAX的应用
Jquery中AJAX的应用
81 0
|
7月前
|
JSON 前端开发 JavaScript
jQuery中ajax的使用
jQuery中ajax的使用
|
7月前
|
XML JavaScript 前端开发
【Web智能聊天客服】之JavaScript、jQuery、AJAX讲解及实例(超详细必看 附源码)
【Web智能聊天客服】之JavaScript、jQuery、AJAX讲解及实例(超详细必看 附源码)
97 0
|
7月前
|
前端开发 JavaScript API
【uni-app】【基于jQuery Ajax】[sd.js]最新原生完整版for凯哥API版本
【uni-app】【基于jQuery Ajax】[sd.js]最新原生完整版for凯哥API版本
|
7月前
|
XML 缓存 JavaScript
jQuery 第十章(jQuery AJAX以及jQuery和其他框架兼容)
jQuery 第十章(jQuery AJAX以及jQuery和其他框架兼容)
55 0