Do NOT translate textarea by jQuery.translator, how?

社会主义新天地 提交于 2019-12-11 05:26:29

问题


I use jQuery.translate, very normal code as:

$('body').translate(...

Now I do not want the textarea and input:text get translated, so I tried:

$('*:not(textarea,:text)').translate(..
$('body *:not(textarea, input:text)').translate(

None working.

(these answers got from another question: jQuery, Select Body but exclude Textarea and Input:Text, how?

Anyone here, has an idea how to translate the body but exclude textarea and input:text, thanks.


回答1:


From the jQuery.translate wiki; first add the notranslate class to the elements you don't want to translate.

$('textarea').addClass('notranslate');
$('input:text').addClass('notranslate');
$('body').translate(...);



回答2:


A nice way to exclude elements from a selector is to use the .not method:

$('*', document.body).not('textarea, input[type=text]').translate(...);



回答3:


Does this work?

$('body').translate( 'es', 'en', { not: 'textarea, input:text' });

(This is translating from Spanish to English, of course.)



来源:https://stackoverflow.com/questions/8631134/do-not-translate-textarea-by-jquery-translator-how

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!