下拉框触发单击事件,在下拉列表上触发点击事件

I have 2 dropdown lists, the first one goes as follows :

{section name=jj loop=$jezyki}

{$jezyki[jj].name}

{/section}

the second one is downloaded from google server, it is a google translate widget.

What i need is when the user clicks on option from the first dropdown, script should change the value of the widget dropdown list AND trigger the click function to actually translate the page.

function changeLang(someth){

var nLang = someth.value;

//$(".goog-te-combo option").val(someth.value);

// $(".goog-te-combo").trigger('click');

$(".goog-te-combo option[value="+nLang+"]").prop('selected',true).click();

}

the snippet above changes the value. I can see, for example, english selected, but still it does not translate the page

解决方案

You need to dispatch onchange event:

function changeLang(someth) {

var nLang = someth.value,

evt = document.createEvent("HTMLEvents");

evt.initEvent("change", false, true);

$('.goog-te-combo').val(nLang)[0].dispatchEvent(evt);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值