根据需求 要做同步翻译 没做过,从网上找了些资料 自己整理的,效果实现了不过 问了我们同事英语编辑人员说有点机械,没办法用人家的东西。我改不了呵呵,
拿出来分享哈,希望大家给点指点。
<body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script language="javascript">
<!--
document.body.onload=adddiv;
document.onmousedown=recordobj;
document.ondblclick=dbclick;
document.onmouseup=showselect;
var starobj,isdb=false,allow=true;
function isallow()
{
if(allow){
allow=false;
alert('is closed');
}
else{
allow=true;
alert('is opend');
}
}
function dbclick()
{
isdb=true;
}
function recordobj()
{
starobj=event.srcElement;
}
function showselect() {
var str="";
if(event.srcElement.tagName!="A"&&event.srcElement.tagName!
="INPUT"&&event.srcElement==starobj&&!isdb&&allow)
{
var oText=document.selection.createRange();
if(oText.text.length>0)
{
str=oText.text;
oText.text="BuB"+oText.text+"EuE";
}
oText.select();
event.srcElement.innerHTML=event.srcElement.innerHTML.replace("BuB","<u style='FONT-WEIGHT:
bold;COLOR: #ff3366'>").replace("EuE","</u>");
}
searchgoogle(str)
isdb=false;
}
function searchgoogle(str)
{
var obj=document.getElementById("searchgoogle");
if(str.length>0)
{
obj.style.display="block";
obj.style.position="absolute";
obj.style.zindex=999;
obj.style.posTop=event.offsetY+2;//
obj.style.posLeft=obj.offsetWidth-40;
//event.offsetX
obj.className='searchgugol'
var vg="";
var tep="网络原因出错";
$.ajax({
url: "http://openapi.baidu.com/public/2.0/bmt/translate?
client_id=2ALMz6WqUEcsBg4BS91Eppq3&from=auto&to=auto" ,
dataType : "jsonp",
jsonnp : 'callback',
type:"get",
data:"q="+encodeURIComponent(str),
success: function(str)
{
obj.innerHTML=str['trans_result'][0]['dst'];
}
});
}
else
{
obj.style.display="none";
}
}
function adddiv()
{
var mobj = document.createElement("div");
mobj.id="searchgoogle";
document.body.appendChild(mobj);
}
function leave(){
var obj=document.getElementById("searchgoogle");
obj.style.display="none";
}
//-->
</script>
<div id="captions">
<a onmouseover=“javascript:searchgoogle(this.innerHTML)” >
and we choose talent for sort of like our halftime.And it's been an amazing thing.it was
Vietnam I think it was probably close to five years ago and we put Lady Gaga on.
</a>
</div>
</body>
</body>