douqiang6036 2014-03-14 11:19
浏览 374
已采纳

在下拉列表中触发单击事件

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>

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

  • 写回答

3条回答 默认 最新

  • doubushi0031 2014-03-14 12:00
    关注

    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);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器