Javascript-based Kingsoft Mac network translation code
Last Update:2018-12-08
Source: Internet
Author: User
:
Note the following Code , It is best to save it as UTF-8 format, otherwise garbled.
Copy code The Code is as follows: <HTML>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> JavaScript Kingsoft network translation </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.doc umentelement;
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.tar get;
$ ("Text_word"). value = element. innerhtml;
Button_translateclick ();
}
</SCRIPT>
<Input id = "text_word" type = "text" value = "hello" onkeydown = "text_wordkeydown (event)"/>
<Input type = "button" value = "Search" 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>