【问题标题】:JQuery textarea wont update after inputting value输入值后JQuery textarea不会更新
【发布时间】:2018-11-21 00:40:32
【问题描述】:

所以我有这个 textarea ,它从 .txt 文件中获取值,效果很好,但是当我在 textarea 中输入新值后更改选择选项时,当所选选项更改时它不会更新。

场景 1: 1.更改选项,textarea更新(OK)

场景 2:(无法更新) 1.更改选项 2.在文本区域输入一些东西 3.更改选择的选项,textarea不会更新!

我为此发布了一个模拟 JSFiddle。即使在 textarea 中输入内容后,如何更新 textarea?

http://jsfiddle.net/jxsew83L/1/

   <section class="content">
  <select name="select_template" id="select_template" class="form-control">
        <option count = '' content = ''>--Select--</option>
    <option count = '' content = 'CONTENT 1'>CONTENT 1</option>
    <option count = '' content = 'CONTENT 2'>CONTENT 2</option>
        </select>


  <div class="descriptionarea">
    <span style="padding: 5px;">Selected Clients <i class="fa fa-fw fa-eye"></i></span><br>
    <textarea id="text_content" name="text_content" rows="10" cols="60" title="" tabindex="0"></textarea><br>
    <span class="buttonfortxtarea"><button id = "btn_id" class= "btn btn-primary btn-flat" count = '' content = ''  filename = ''>SEND</button></span>
  </div>
</section>

对于 Jquery

     $(document).on("change", "#select_template", function(e) {
   var content = $('option:selected', this).attr('content');
   var count = $('option:selected', this).attr('count');
   var filename = $('option:selected', this).attr('filename');
   $(this).parent().parent().find('#text_content').html('');
   $(this).parent().parent().find('#text_content').value(content);

   $(this).parent().parent().find('#btn_id').attr('count', count);
   $(this).parent().parent().find('#btn_id').attr('filename', filename);


 });

【问题讨论】:

    标签: javascript jquery html


    【解决方案1】:

    在你的小提琴中,换行

    $(this).parent().parent().find('#text_content').html(content);
    

    $(this).parent().parent().find('#text_content').val(content);
    

    似乎解决了问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-08
      • 1970-01-01
      • 1970-01-01
      • 2016-12-29
      • 1970-01-01
      • 2013-06-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多