如何将用户输入传递到其他文本区域

How do I pass on the user input to a other textarea?

本文关键字:其他 文本 区域 用户 输入      更新时间:2023-09-26

>我有两个输入字段。不知道如何将用户输入从第一个传递到第二个,以便它同时添加相同的文本。有人可以帮助我吗?

<h1>1. How should the perfect world look like?</h1>
<input id="perfectworld" class="" name="perfectworld_des" type="text" placeholder="How should the perfect world look like?" size="65" />
<script type="text/javascript">
function select_all()
{
var text_val=eval("document.form1.type");
text_val.focus();
text_val.select();
}
</script>
<form name=form1 method=post action=''''>
<textarea name=type rows=3 cols=35 onClick="select_all();">In a perfect world (Input from frist form goes here) @TwitterName #HASHTAG</textarea>
</form>
您只需

在输入字段上使用 keyup 事件。当事件触发时,将文本的一部分替换为给定的值,并在文本区域中插入该新文本。使用jQuery,我可以给你一个小例子:

var myinput = $('#perfectworld');
var mytext = $('#mytext');
var giventext = 'In a perfect world #placeholder# @TwitterName #HASHTAG';
myinput.keyup(function() {
    var value = $(this).val();
    var newtext =  giventext.replace('#placeholder#', value);
    mytext.html(newtext);
});

看看jsfiddle:http://jsfiddle.net/3by2a5v1/