2017-06-10 36 views
6

Robię aplikację internetową opartą na języku tamilskim. W Mojej aplikacji użyłem Dynamicznych pól do dodania danych użytkownika. Tak więc, pola dynamiczne mają wiele identyfikatorów, jak to zrobić lub jak używać transliteracji Google opartej na klasie?Jak zrobić transliterację Google opartą na klasie nie Id

<script type="text/javascript" src="http://www.google.com/jsapi"></script> 
<script type="text/javascript"> 
    // Load the Google Transliteration API 
    google.load("elements", "1", { 
    packages: "transliteration" 
    }); 

    function onLoad() { 
    var options = { 
     sourceLanguage: 'en', 
     destinationLanguage: 'ta', 
     shortcutKey: 'ctrl+m', 
     transliterationEnabled: true 
    }; 

    // Create an instance on TransliterationControl with the required 
    var control = new google.elements.transliteration.TransliterationControl(options); 

    // Enable transliteration in the textfields with the given ids. 
    var ids = ['temrorary_address', 'permanant_address', 'bankbranch', 'member_name', 'father_husband', 'workingoffice_address', ]; 
    control.makeTransliteratable(ids); 

    // Show the transliteration control which can be used to toggle between 
    // English and Hindi and also choose other destination language. 
    control.showControl('translControl'); 
    } 
    google.setOnLoadCallback(onLoad); 
</script> 

Odpowiedz

1

makeTransliteratable wejściowy może być nie tylko identyfikatorów, lecz szereg elementów odniesienia, jak również. Więc można napisać:

// Enable transliteration in the textfields with the given Class. 
var elements = document.getElementsByClassName('Type-Your-Class-Here'); 
control.makeTransliteratable(elements); 

Ale jeśli dodajesz dynamicznie pola, to nie pomaga. W przypadku dynamicznie dodawanych pól musisz zadzwonić pod numer control.makeTransliteratable za każdym razem, gdy dodasz nowe pole.