通过使用jQuery单击第三个元素,使用textarea动态更改段落文本? [英] Change paragraph text dynamically with textarea by clicking third element with jQuery?

查看:184
本文介绍了通过使用jQuery单击第三个元素,使用textarea动态更改段落文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过点击第三个元素在另一个textarea中显示书写的textarea文本。
这里是我现在使用的代码,但它显示了当你按下 textarea 时的书面文本:

I want to display written textarea text in another textarea by clicking a third element. So here's the code I'm using at the moment but it shows the written text when you press the textarea:

  $(function(){
    $('#text').click(function(){
      $('#preview').text($(this).val());
    });
  });

这里是HTML部分:

<textarea id="text"></textarea>
<textarea id="preview"></textarea>

<div id="show-text"></div>

所以这个想法是在textarea#text中显示textarea#显示文本。

So the idea is to display the text inside textarea#text in textarea#preview when you click div#show-text.

推荐答案

您的问题是您的点击事件在textarea上注册。您实际寻找的是:

Your problem is that your click event is registered on the textarea. What you're actually looking for is:

  $(function(){
     $('#show-text').click(function(){
       $('#preview').text($('#text').val());
     });
   });

这篇关于通过使用jQuery单击第三个元素,使用textarea动态更改段落文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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