如何通过我的事件处理程序试用自定义小部件
我有 this 代码:
<a href="http://www.mypage.com">Translate (to italiano) piloting the Google Translate Tools</a>
<div id="boxSelLingue">
<div id="google_translate_element"></div>
<script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement({
pageLanguage: 'en'
}, 'google_translate_element');
}
</script>
<script type="text/javascript" src="http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
</div>
<div id="myText">
This is my text in the page to translate
</div>
您可以看到,从选择框中更改语言,页面将翻译自动地。现在,我想从另一个来源尝试这种行为;在示例中,通过链接使用 Google 翻译工具进行翻译(翻译为意大利语)
所以我所做的是:
$('#myLink').click(function(e) {
e.preventDefault();
// I select the destination language, (it)alian
var idLingua = "it";
$('#boxSelLingue select').val(idLingua);
$('#boxSelLingue select option').click();
});
如何see,点击链接会更改google选择框的选定值,但我真的不知道哪个事件调用真正的google服务(应该翻译页面) 。我想是change()或click(),但是:
$('#boxSelLingue select option').click();
$('#boxSelLingue select option').change();
没有任何反应!事实上它不起作用。在我看来,谷歌用来调用他的服务(更改 select 的值)的唯一方法是在 select 上附加一个事件处理程序......
我该怎么做?
I have this code :
<a href="http://www.mypage.com">Translate (to italiano) piloting the Google Translate Tools</a>
<div id="boxSelLingue">
<div id="google_translate_element"></div>
<script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement({
pageLanguage: 'en'
}, 'google_translate_element');
}
</script>
<script type="text/javascript" src="http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
</div>
<div id="myText">
This is my text in the page to translate
</div>
how you can see, changing the language from the select box, the page will translate automatically. Now, I'd like to pilot this behaviour from another source; In the example, from the link Translate (to italiano) piloting the Google Translate Tools
So what I've done is :
$('#myLink').click(function(e) {
e.preventDefault();
// I select the destination language, (it)alian
var idLingua = "it";
$('#boxSelLingue select').val(idLingua);
$('#boxSelLingue select option').click();
});
how you can see, clicking on the link change the selected value of the google select box, but I really don't know which event call the real google service (which should translate the page). I suppose it was change() or click(), but with :
$('#boxSelLingue select option').click();
$('#boxSelLingue select option').change();
nothing happens! In fact it doesnt works. The only way that google use to call his service (changing the value of select) is to attach an event handler on the select, in my opinion...
How can I do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论