How to Change CSS direction property of the input field automaticly if the user can use an language rtl or ltr

前端 未结 5 893
失恋的感觉
失恋的感觉 2021-02-06 08:49

Example: if I use arabic language the text field direction will be rtl and if I want to write a new text and I switch to the English language the direction inside the text field

5条回答
  •  隐瞒了意图╮
    2021-02-06 09:16

    thanks for you help, I used javascript to resolve this problem , in this code I used jquery framework and it work only for Arabic language , for others language you must edit charCodeAt(0) comparison value.

    $('#input_ar').keyup(function(){
        if ((($(this).val().charCodeAt(0) > 0x600) && ($(this).val().charCodeAt(0) < 0x6FF)) || ($(this).val()=="")) { $('#search_input').css("direction","rtl"); }
        else { $('#search_input').css("direction","ltr"); }
    });
    

提交回复
热议问题