当前位置: 首页 > 图文教程 > 网络编程 > Javascript > javascript实现的基于金山词霸网络翻译的代码

Javascript
动态改变图片尺寸(一)
JavaScript+PHP 应用一:网页制作中双下拉菜单的动态实现
JavaScript + PHP 应用二:网页设计中树形菜单的动态实现
在Javascript中为String对象添加trim,ltrim,rtrim方法
纯JavaScript时钟
网页之定时器详解
为网页添加活动的背景音乐
Javascript Game
实用的检测分辨率的程序代码
【推荐】一个非常漂亮的列表框
绝对精彩:在网页里做类似window右键的弹出式菜单
怎样使网页中的元素可编辑??
JavaScript和Java的区别
怎样编写IE和NN6通用的闪烁(blank)效果
关于如何动态地在同一页面实现两个 < select > 互传 (s1 <==> s2)
COOKIE欺骗
连串英文自动换行的方法
JavaScript中的正则表达式(1)
JavaScript中的正则表达式(2)
JavaScript窗口功能指南之定制新窗口

Javascript 中的 javascript实现的基于金山词霸网络翻译的代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-20   浏览: 53 ::
收藏到网摘: n/a

下面的这段代码是基于金山词霸网络翻译提供的接口,远程调用文件,可以作为一个自定义的在线查询工具。 上图:

注意下面的代码,最好保存为utf-8格式的,要不容易出现乱码。
复制代码 代码如下:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>javascript 金山词霸在线网络翻译 </title>
</head>
<body>
<script type="text/javascript">
function $(id) { return document.getElementById(id); }
function callScript(url, loaded, error, charset) {
var script = document.createElement("script");
if (typeof charset == "string") script.charset = charset;
script.onreadystatechange = function() {
switch (this.readyState) {
case "complete":
case "loaded":
if (typeof loaded == "function") loaded();
if (script.parentNode) script.parentNode.removeChild(script);
break;
}
}
script.onload = function() {
if (typeof loaded == "function") loaded();
if (script.parentNode) script.parentNode.removeChild(script);
}
script.onerror = function() {
if (typeof error == "function") error();
if (script.parentNode) script.parentNode.removeChild(script);
}
script.type = "text/javascript";
script.defer = "true";
script.src = url;
var parent = document.getElementsByTagName("HEAD")[0] || document.documentElement;
if (parent && parent.insertBefore) parent.insertBefore(script, parent.firstChild);
}
function button_translateClick() {
var word = encodeURIComponent($("text_word").value);
if (!word) {
alert('');
$("text_word").focus();
return;
}
callScript("http://server.dict-co.iciba.com/jsInterface.php?uiType=0&w=" + word + "&type=6");
callScript("http://server.dict-co.iciba.com/jsInterface.php?uiType=0&w=" + word + "&dict=Dict,Tf,Enen,");
callScript("http://server.dict-co.iciba.com/jsInterface.php?uiType=0&w=" + word + "&dict=Dict,Tf,Enen,");
callScript("http://server.dict-co.iciba.com/jsInterface.php?uiType=0&w=" + word + "&type=2");
}
function text_wordKeydown(e) {
if (!e) e = window.event;
switch (e.keyCode | e.which | e.charCode) {
case 13:
button_translateClick();
break;
}
}
function LoveCallback(context) {
$("div_context").innerHTML = context;
}
function dictCallBack(context) {
$("div_head").innerHTML = context;
}
function tfCallback(context) {
$("div_thesaurus").innerHTML = context;
}
function En2enCallback(context) {
$("div_en2en").innerHTML = context;
}
function djCallback(context) {
$("div_dj").innerHTML = context;
}
function searchDictByWord(e) {
var element = typeof event != "undefined" ? event.srcElement : e.target;
$("text_word").value = element.innerHTML;
button_translateClick();
}
</script>
<input id="text_word" type="text" value="hello" onkeydown="text_wordKeydown(event)" />
<input type="button" value="搜索" onclick="button_translateClick()"/>
<div id="div_head"></div>
<div id="div_context"></div>
<div id="div_thesaurus"></div>
<div id="div_en2en"></div>
<div id="div_dj"></div>
</body>
</html>