Jquery Click Handler Not Working After Two Times

后端 未结 1 2036
无人及你
无人及你 2021-01-21 09:33

I am facing a little strange problem. I am using bing translator (http://www.bing.com/widget/translator) and trying to customize it on my own using their API.

Here is my

相关标签:
1条回答
  • 2021-01-21 10:27

    It seems that Microsoft script changes the HTML structure during the translation process. Because of this you have to use delegation: instead of $("#changeLang a").on("click", handler) you will do $('#changeLang').on("click", "a", handler). Also, your code can be simplified:

    var lang;
    $('#changeLang').on("click", "a", function (e) {
        var to = $(this).attr('id');
        console.log("Translating from ", lang, " to ", to);
        Microsoft.Translator.Widget.Translate(lang, to);
        lang = to;
    });
    

    JSFIDDLE

    0 讨论(0)
提交回复
热议问题