如何在用户单击按钮时将文本添加到textarea [英] How to add text to textarea when user clicks a button

查看:159
本文介绍了如何在用户单击按钮时将文本添加到textarea的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在用户点击按钮时将文本添加到textarea。我知道如何连接字符串并将其添加到textarea,但是我想要的是将文本添加到textarea内的位置/位置,用户在其中单击,然后添加文本

预先致谢

解决方案

这里是来自我的参考资料:

 < script> 
函数input(){
var text =这里是您要输入的文本。;
document.forms.form1.area.value = text;
}
< / script>
< form name ='form1'>
点击< input onclick ='input()'type ='button'value ='BUTTON'id ='button'>< br>
< textarea name ='area'>< / textarea>

< / form>

表示一个示例,显示当一个按钮被点击时,一行文本添加到textarea中。
为什么我在其中添加了javascript?因为html属性只是不足以让它成为它。

可能会有帮助:D

I want to add text to textarea when user clicks a button.I know how to concate string and add it to textarea but what i want is to add text to the place/position inside textarea where users clicks and then add text in that position on clicking button.

Thanks in advance

解决方案

Here's a reference from me:

<script>
function input(){
    var text = "here the text that you want to input.";
    document.forms.form1.area.value = text;
}    
</script>
<form name='form1'>
    Click<input onclick='input()' type='button' value='BUTTON' id='button'><br>
    <textarea name='area'></textarea>

</form>

that an example that showing when a button clicked, a row of text added to textarea. why do i added javascript in it? because html attributes only is not enough to make it.
may it help :D

这篇关于如何在用户单击按钮时将文本添加到textarea的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆