上图:
注意下面的代码,最好保存为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>
注意下面的代码,最好保存为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>
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com
暂无“javascript实现的基于金山词霸网络翻译的代码”评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。