我正在尝试使用Google Translate触发西班牙语翻译,并且找到了一些使用jQuery进行翻译的选项。我已经能够从下拉列表中选择西班牙语,但是它不会触发change事件来启动翻译过程。有人可以看一下,告诉我我做错了吗?
谢谢
<!DOCTYPE html>
<html lang="en-US">
<head>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$('.goog-te-combo').change(function(){
var data= $(this).val();
alert(data);
});
$('.goog-te-combo')
.val('es')
.trigger('change');
});
});
</script>
<script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement({pageLanguage: 'en'}, 'google_translate_element');
}
</script>
<script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
</head>
<body>
<div id="google_translate_element"></div>
<h2>This is a test.</h2>
<p>Trying to accomplish translating this text into Spanish using Google Translate via a button click.</p>
<p>Just some random text to make sure this works.</p>
<button>Hablamos Espanol</button>
</body>
</html>