- <!---
- if(typeof lan=="undefined"){
- var lan="en";
- }
- if(typeof size=="undefined"){
- var size="1";
- }
- function outerWidth(el){
- if(typeof(el)=="string"){el=document.getElementById(el);}
- var retWidth = el.offsetWidth;
- if(el.style){
- retWidth+=el.style.paddingLeft?parseInt(el.style.paddingLeft):0;
- retWidth+=el.style.paddingRight?parseInt(el.style.paddingRight):0;
- retWidth+=el.style.borderRightWidth?parseInt(el.style.borderRightWidth):0;
- retWidth+=el.style.borderLeftWidth?parseInt(el.style.borderLeftWidth):0;
- retWidth+=el.style.marginLeft?parseInt(el.style.marginLeft):0;
- retWidth+=el.style.marginRight?parseInt(el.style.marginRight):0;
- }
- return retWidth;
- }
- function innerWidth(el){
- if(typeof(el)=="string"){el=document.getElementById(el);}
- var retWidth = el.offsetWidth;
- if(el.style){
- retWidth-=el.style.paddingLeft?parseInt(el.style.paddingLeft):0;
- retWidth-=el.style.paddingRight?parseInt(el.style.paddingRight):0;
- retWidth-=el.style.borderRightWidth?parseInt(el.style.borderRightWidth):0;
- retWidth-=el.style.borderLeftWidth?parseInt(el.style.borderLeftWidth):0;
- }
- return retWidth;
- }
- var html="<input type='text' id='hjdictword' /><a id='dict_clicklink' href='###' target='_blank'><img src='http://dict.hujiang.com/images/btn_dict_small.gif' align='absmiddle' border='0' alt='点击查词'/></a>";
- function hj$keydown(aevent)
- {
- if(!aevent){
- aevent= window.event;
- }
- if( aevent.keyCode==13){
- try{
- var aword=hj$('hjdictword').value;
- window.open( hj$getDictLink(aword));
- return false;
- }catch(e){
- var aword=hj$('hjdictword').value;
- aword = aword.split(" ").join("+");
- window.open( hj$getDictLink(aword) );
- }
- }
- }
- function hj$(aObjID){
- return document.getElementById(aObjID);
- }
- <!-- 值需要修改下面的路径就可以使用了 -->
- function hj$getDictLink(aword){
- if(lan=="en"){
- return 'http://localhost/modules.php?c_word='+ encodeURI(aword);
- }else if(lan=="jp"){
- return 'http://localhost/modules.php?c_word='+ encodeURI(aword);
- }else {
- return 'http://localhost/modules.php?c_word='+ encodeURI(aword);
- }
- }
- function hj$click(){
- var aword=hj$('hjdictword').value;
- if(aword.length>0 && aword!=""){
- aword = aword.split(" ").join("+");
- hj$('dict_clicklink').href=hj$getDictLink(aword) ;
- return true;
- }else{
- hj$('hjdictword').value="Please enter the words";
- return false;
- }
- }
- function hj$AutoSize(){
- hj$('hjdictword').style.width =innerWidth( hj$('hjdictword').parentNode) - outerWidth('dict_clicklink')- 17 ;
- }
- if( Html=="1"){
- document.write(Html);
- }else{
- if( hj$("hjdictword")==null){
- document.write(Html);
- }
- }
- hj$('dict_clicklink').onclick= hj$click;
- hj$('hjdictword').onkeydown= hj$keydown;
- hj$('hjdictword').onmouseover= function(){
- this.focus();
- if(lan=="en"){
- this.title="Please enter the English or Chinese word."
- }else if(lan=="jp"){
- this.title="Please enter the Japanese or Chinese word."
- }
- }
- if(size=="1"){
- setTimeout("hj$AutoSize();", 100);
- };
- -->
- //该片段来自于http://www.codesnippet.cn/detail/021220137645.html
来源: http://www.codesnippet.cn/detail/021220137645.html