javascript 使用金山词霸网络翻译(转自优快云)

 

<html>
<head>
<title>金山词霸 -- 微型网络版</title>
</head>
<body>
<script type="text/javascript">
/*
设计:王集鹄(http://blog.youkuaiyun.com/zswang)
日期:2009年5月18日
版权:http://www.iciba.com
*/
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>

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值