2017-06-10 13 views
6

我正在做基於泰米爾語言的Web應用程序。在我的應用程序中,l使用動態字段添加用戶詳細信息。所以,動態字段有多個ID如何做到這一點或如何使用基於類的Google音譯?如何做基於類的Google音譯不是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> 

回答

1

makeTransliteratable輸入不僅可以是一個ID數組,也可以是元素引用。 所以你可以這樣寫:

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

但是如果你動態地添加字段,它並不能幫助。對於動態添加的字段,每次添加新字段時都必須撥打control.makeTransliteratable