【问题标题】:textarea value update without delete the previous Javascripttextarea 值更新而不删除之前的 Javascript
【发布时间】:2020-03-22 18:32:08
【问题描述】:

我正在尝试在文本区域中插入新数据而不影响上一个:

<textarea class="form-control" rows="5" id="data" name="data">
roma is the most visit
</textarea>

  $("#data").val('new line without delete the previous one ');

我的期望:

<textarea class="form-control" rows="5" id="data" name="data">
roma is the most visit
new line without delete the previous one 
</textarea>

那我该怎么做呢?

【问题讨论】:

    标签: javascript jquery javascript-objects jquery-events


    【解决方案1】:

    使用.append() 代替.val() (doc):

    $("#data").append('new line without delete the previous one ');
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <textarea class="form-control" rows="5" id="data" name="data">
    roma is the most visit
    </textarea>

    【讨论】:

      猜你喜欢
      • 2015-04-27
      • 2023-03-17
      • 1970-01-01
      • 2021-10-22
      • 1970-01-01
      • 1970-01-01
      • 2016-01-29
      • 2018-09-30
      • 2012-02-04
      相关资源
      最近更新 更多