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