zoukankan      html  css  js  c++  java
  • javascript 使用金山词霸网络翻译

    <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>
    
    
    

    啥也不说了 上图:

    没有目标的人都只在帮有目标的人完成目标

  • 相关阅读:
    使用std::accumulate计算和、积和平均值
    Boost文件读写,断言、日期
    mem_fun的用法,以及使用wcout
    singleton的内存泄漏及线程安全性问题
    delphi关键字
    Windows Api的一些方法 封装 以及 常用参数
    linux字符设备驱动 自动创建设备节点的的方法
    Linux混杂设备注册方法
    linux2.6字符设备的标准注册方法
    另一种linux下的powerpc中断注册的方法
  • 原文地址:https://www.cnblogs.com/tweet/p/1648567.html
Copyright © 2011-2022 走看看