简体   繁体   中英

How to change textbox to textarea

I am using the following code for selecting font family from drop down list to textbox. Now I want to use textarea in place of text box. How can I do this?

<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>

I tried

You can change:

<input type="text" name="text1" value="Font Family" />

to:

<textarea>Font Family</textarea>

then use:

$('textarea').css('font-family', this.value);

instead of:

$('input[name="text1"]').css('font-family', this.value);

Fiddle Demo

尝试,

<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 />');

try something like this

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 + '" />';
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM