[英]How to append values to a text area using javascript
I have a text area which is generating randomly with different id 我有一个文本区域正在随机生成具有不同ID的文本
<textarea id=t"+i+" placeholder="+["Html","CSS","Js"][i]+" rows=9></textarea>
This text area is having ids from t0 to t3 what i want to do is that i want to append values to this text area using javascript how can i do that?. 这个文本区域具有从t0到t3的ID,我想做的是我想使用JavaScript将值附加到此文本区域,我该怎么做? The value generation should be happen before creating dom
价值创造应在创建dom之前进行
I suppose you're generating the html. 我想您正在生成html。 If so, you can use
attribute selector
with begins-with operator. 如果是这样,则可以将
attribute selector
与begins-with运算符一起使用。
$('[id^=t]').val('some value');
Note that this sets value for all elements which have their ids beginning with t
. 请注意,这会为所有ID以
t
开头的元素设置值。 So be careful when using ids starting with t
and if you know before hand the number after t
, then you can just target that element. 因此,在使用以
t
开头的id时要格外小心,如果您事先知道t
后面的数字,那么您可以直接定位该元素。
$('#t' + id).val('some value');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.