本文實例講述了jQuery實現的中英文切換功能。分享給大家供大家參考,具體如下:
1.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>中英文切換</title><script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script><script type="text/javascript" src="js/language.js"></script></head><body> <button id="change">中英文切換</button> <div style="text-align: center"> 你好 </div></body><script type="text/javascript"> $("#change").click(function() { translate(); })</script></html>
2.language.js
$(function(){ // do something var script=document.createElement("script"); script.type="text/javascript"; script.src="js/translate.js"; document.getElementsByTagName('head')[0].appendChild(script); var value = sessionStorage.getItem("language"); document.onreadystatechange = function () { if (document.readyState == 'complete') { if(value==="1"){ Microsoft.Translator.Widget.Translate('zh-CHS', 'en', onProgress, onError, onComplete, onRestoreOriginal, 2000); } } } function onProgress(value) { } function onError(error) { } function onComplete() { $("#WidgetFloaterPanels").hide(); } function onRestoreOriginal() { }});function translate(){ var value = sessionStorage.getItem("language"); if(value==="1"){ sessionStorage.setItem("language", "0"); }else{ sessionStorage.setItem("language", "1"); } window.location.reload();//刷新當前頁面.}
3.translate.js是將http://www.microsoftTranslator.com/ajax/v3/WidgetV3.ashx?siteData=ueOIGRSKkd965FeEGM5JtQ**的源碼下載下來的,并將里面
<1> J = "block", ib = "inline-block",都改成等于none
<2>s.style.color = q;s.style.backgroundColor = p兩行注釋
目的是去除翻譯后出現的彈框和hover效果
最后:
附:完整實例代碼點擊此處本站下載。
更多關于jQuery相關內容感興趣的讀者可查看本站專題:《jQuery擴展技巧總結》、《jQuery表格(table)操作技巧匯總》、《jQuery常見經典特效匯總》、《jquery選擇器用法總結》及《jQuery常用插件及用法總結》
希望本文所述對大家jQuery程序設計有所幫助。
新聞熱點
疑難解答