作家
登录

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

作者: 来源:www.28hudong.com 2013-03-30 01:56:16 阅读 我要评论

上图: 注意下面的代码,最好保存为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>

  推荐阅读

  AJAX的跨域与JSONP(为文章自动添加短址的功能)

什么是AJAX的跨域请求 出于安全的考虑,如果你要从www.a.com通过Ajax来请求另外一个网站www.b.com的内容,浏览器是不允许你这样做的(不理解这里的安全是指什么?想想如果没有这个限制的话,黑客可以做些什么)。那>>>详细阅读


本文标题:javascript实现的基于金山词霸网络翻译的代码

地址:http://www.17bianji.com/kaifa2/JS/27227.html

关键词: 探索发现

乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

网友点评
自媒体专栏

评论

热度

精彩导读
栏目ID=71的表不存在(操作类型=0)