javascript 使用金山词霸网络翻译

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<html>
<head>
<title>金山词霸 -- 微型网络版</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>

 

啥也不说了 上图:

 

posted @   Tweet  阅读(327)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系统下SQL Server数据库镜像配置全流程详解
· 现代计算机视觉入门之:什么是视频
· 你所不知道的 C/C++ 宏知识
· 聊一聊 操作系统蓝屏 c0000102 的故障分析
· SQL Server 内存占用高分析
阅读排行:
· 盘点!HelloGitHub 年度热门开源项目
· DeepSeek V3 两周使用总结
· 02现代计算机视觉入门之:什么是视频
· C#使用yield关键字提升迭代性能与效率
· 回顾我的软件开发经历(1)
点击右上角即可分享
微信分享提示