Javascript for loop to change the name of textareas in a function
问题 I have created 50 textareas with names def1,def2,def3.....,def50 . In my body onLoad() function,I want the same value is set in all these textboxes. Instead of writing the code 50 times, How can I write some Javascript code to set the value of the textarea , ie in a loop? 回答1: I suggest to read the MDC JavaScript guide, as loops and string concatenation are fairly basic operations: for(var i = 1; i < 51; i++) { var nameOfTextarea = 'def' + i; // ... } 回答2: I would give your textboxes ID's