[英]How to Change HTML Tags Using Javascript
I have some HTML code that looks like this: 我有一些看起来像这样的HTML代码:
<textarea name="message"></textarea>
And I would like to change it to this: 我想将其更改为:
<textarea maxlength="300" name="message"></textarea>
How can I accomplish this using Javascript? 如何使用Javascript完成此操作? I have tried a lot of different code from a lot of different places, but none of them seem to work.
我在许多不同的地方尝试了很多不同的代码,但是似乎都没有用。 If need be, I will accept CSS code too.
如果需要,我也将接受CSS代码。
使用jquery匹配tag元素,然后使用.attr()函数。
document.querySelector('[name="message"]').setAttribute('maxlength', 300)
$('textarea').attr('maxlength', 300);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.