且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用jQuery将输入元素更改为textarea

更新时间:2023-10-25 16:34:10

jQuery有一个.replaceWith()方法,可用于将一个元素替换为另一个元素.因此,请从输入中复制样式,并使用此方法,如下所示:

jQuery has a .replaceWith() method you can use to replace one element with another. So, copy your styles from the input and use this method, as follows:

$('input[size="100"]').each(function () {
    var style = $(this).attr('style'),
        textbox = $(document.createElement('textarea')).attr('style', style);
    $(this).replaceWith(textbox);
});

演示