在下拉列表上触发点击事件 [英] Trigger click event on a dropdown list

查看:854
本文介绍了在下拉列表上触发点击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个下拉列表,第一个如下:

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

<select name="country_id" id="country_id" tabindex="1" onchange="changeLang(this);">

    {section name=jj loop=$jezyki}            

        <option value="{$jezyki[jj].code}" {if $LANG.lang == $jezyki[jj].code} selected {/if}>{$jezyki[jj].name}</option>

    {/section}  
</select>

第二个是从google服务器下载的,它是一个google翻译窗口小部件. 我需要的是,当用户从第一个下拉列表中单击选项时,脚本应更改小部件下拉列表的值并触发单击功能以实际翻译页面.

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

推荐答案

您需要调度onchange事件:

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);
}

这篇关于在下拉列表上触发点击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆