使用类名向文本区添加文本

Add text to textarea using class name

本文关键字:文本区 添加 文本      更新时间:2023-09-26

当用户单击标记时,我想使用类名在textarea中添加附加文本。

单击事件处理程序工作,但不能向文本区域添加文本。

这是我到目前为止的代码。

var boardName;
$(document).ready(function() {
    $('.js-open-card-composer').click(function() {
         boardName = document.title.replace(' | Trello', '');
         $('.list-card-composer-textarea').text += boardName;
    });
});

这里是文本区域

<textarea class="list-card-composer-textarea js-card-title" style="overflow: hidden; word-wrap: break-word; height: 36px;"></textarea>

谢谢!

jQuery text() is function

$('.list-card-composer-textarea').text += boardName;
使用

var data = $('.list-card-composer-textarea').text();
$('.list-card-composer-textarea').text( data + boardName);

使用html代替文本

var boardName;
    $('.js-open-card-composer').click(function() {
         boardName = 'test';
         var data = $('.list-card-composer-textarea').html();
         $('.list-card-composer-textarea').html(data+boardName);
    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textarea class="list-card-composer-textarea js-card-title" style="overflow: hidden; word-wrap: break-word; height: 36px;"></textarea>
<div class="js-open-card-composer" style="width:20px;height:20px;border:1px solid red"></div>