Change paragraph text dynamically with textarea by clicking third element with jQuery?

人盡茶涼 提交于 2019-12-14 02:38:52

问题


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());
    });
  });

And here's the HTML part:

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

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

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


回答1:


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());
     });
   });


来源:https://stackoverflow.com/questions/13982727/change-paragraph-text-dynamically-with-textarea-by-clicking-third-element-with-j

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!