[英]How to change textbox to textarea
我正在使用以下代码从下拉列表到文本框选择字体系列。 现在,我想使用textarea代替文本框。 我怎样才能做到这一点?
<HTML>
<head>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script>
$(function () {
$('select[name="font"]').on('change', function () {
$('input[name="text1"]').css('font-family', this.value);
});
});
</script>
</head>
<body>
Select Programming font:
<select name="font">
<option value="arial">arial black</option>
<option value="tohma">tahoma</option>
<option value="times new roman">times new roman</option>
<option value="calibri">calibri</option>
</select>
<br>EnterValue:
<input type="text" name="text1" value="Font Family">
</body>
</html>
我试过了
你可以改变:
<input type="text" name="text1" value="Font Family" />
至:
<textarea>Font Family</textarea>
然后使用:
$('textarea').css('font-family', this.value);
代替:
$('input[name="text1"]').css('font-family', this.value);
尝试,
<textarea name="text1" id="text1">Font Family</textarea>
<input id="text-input" type="text" name="text1" value="Font Family">
var value = $('#text-input').val();
$('#text-input').replace('<textarea id="text-input" name="text1"></textarea >');
$('#text-input').val(value);
您可以使用replaceWith方法将输入框更改为texarea,如下所示:
$('input[name="text1"]').replaceWith('<textarea />');
尝试这样的事情
function t2t( el ) {
var element = document.getElementById( el.id );
var parent = element.parentNode;
parent.removeChild( element );
parent.innerHTML = element.type == 'text' ? '<textarea id="' + element.id + '" cols=50 rows=5>' + element.value +'</textarea>' : '<input type="text" id="' + element.id + '" value="' + element.value + '" />';
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.