如何在输入类型=“文本"之间切换和 textarea 使用 jquery [英] how to switch between input type="text" and textarea using jquery
本文介绍了如何在输入类型=“文本"之间切换和 textarea 使用 jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请帮助我解决此代码或使用 jquery 在 input type="text" 和 textarea 之间切换的其他工作代码.
please help me on this code or another working code that switch between input type="text" and textarea using jquery.
$(function(){
$("a#change").toggle(function(){
var input = document.getElementById('text'),
textarea = document.createElement('textarea');
textarea.id = input.id;
textarea.cols = 40;
textarea.rows = 5;
textarea.value = input.value;
input.parentNode.replaceChild(textarea,input);
return false;
},function(){
textarea.parentNode.replaceChild(input,textarea);
return false;
});
});
<input type="text" name="text" id="text" /><a href="#" id="change">change</a>
推荐答案
以下内容应该适合您.
var textbox = $("#textbox");
var textarea = $("<textarea id='textarea'></textarea>");
$("#change").click(function () {
//Check for textbox or textarea
if ($("#textbox").length === 1) {
//Copy value to textarea
textarea.val(textbox.val());
//Replace textbox with textarea
textbox = textbox.replaceWith(textarea);
} else {
//Copy value to textbox
textbox.val(textarea.val());
//Replace textarea with textbox
textarea = textarea.replaceWith(textbox);
}
});
您可以根据需要设置第二行的 cols 和 rows.
You can set the cols and rows in line two in you need to.
这篇关于如何在输入类型=“文本"之间切换和 textarea 使用 jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文