jQuery 将输入类型=文本更改为文本区域
我有一个隐藏字段。在放置事件之后,它需要转换为“文本区域”。
这:
excerpt = $(parent).find('#excerpt').attr('type', 'textarea');
excerpt.val('textarea');
产生
属性无法更改
错误
此方法: 将元素类型从隐藏更改为输入
marker = $('<span />').insertBefore('#myInput');
$('#myInput').detach().attr('type', 'textarea').insertAfter(marker);
marker.remove();
使用“textarea”不执行任何操作' ,但仅适用于 'text'。添加:
.val('HERE')
到 :
$('#myInput').detach().attr('type', 'textarea').val('HERE').insertAfter(marker);
行确实会导致文本框的值发生变化,因此选择器正在工作并且正在插入 元素和正确删除。
这是一个无法克服的安全问题吗?或者有办法做到吗?
I have a hidden field . After a drop event it needs to be transformed to a 'textarea'.
This:
excerpt = $(parent).find('#excerpt').attr('type', 'textarea');
excerpt.val('textarea');
Produces the
property cannot be changed
error
This method :
Change element type from hidden to input
marker = $('<span />').insertBefore('#myInput');
$('#myInput').detach().attr('type', 'textarea').insertAfter(marker);
marker.remove();
Does nothing using 'textarea' , but works for just 'text'.Adding:
.val('HERE')
To the :
$('#myInput').detach().attr('type', 'textarea').val('HERE').insertAfter(marker);
line does result in the value of the the text box changing , so the selector is working and the <span>
element is being inserted and removed correctly.
Is this an insurmountable security issue? Or is there a way of doing it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
由于
textarea
与input
是完全不同的元素,因此更容易创建一个新的textarea
并删除input
。试试这个:Because a
textarea
is a completely different element toinput
it's easier to simply create a newtextarea
and remove theinput
. Try this:您始终可以删除要更改的元素并添加新元素...
You can always remove the element you want to change and add a new one...
您面临的问题是 TextArea 是一个元素而不是属性。
您应该删除以前的元素并替换为同名的新文本区域:
The problem you face is that TextArea is a an element not an attribute.
You should look to remove the previous element and replace with a new text area of the same name: