为了向文本区域添加值,我从jquery函数中缺少什么

What am i missing from jquery function in order to add value into a textarea

本文关键字:函数 jquery 什么 我从 文本 区域 添加      更新时间:2023-09-26

用户单击"添加"按钮后,我正在尝试将一些内容添加到文本区域中,但没有任何反应。我缺少什么吗?

下面是添加所选内容的 jquery 代码:

         $(".add").on("click", function(event) {
    console.log("clicked");
    //lets get our Question Text... 
    var theQuestion = $("td:first-child", $(this).parent()).text();
    //the row is present, let's then make sure that the proper cell gets oru data. 
    if ($('.activePlusRow').length > 0) {
        $('.activePlusRow').next('.textAreaQuestion').val(theQuestion);
        $('.activePlusRow').removeClass('activePlusRow');
    }
});
 $(".plusrow").on("click", function(event) {
    //adding a unique class for the purpose of the click. 
    $(this).addClass('activePlusRow');
});

下面是文本区域:

  $('.questionTextArea').each( function() {
    var $this = $(this);
    var $questionText = $("<textarea class='textAreaQuestion'></textarea>").attr('name',$this.attr('name')+"[]")
                   .attr('value',$this.val());

    });

编辑:

您可以使用该应用程序亲自查看。以下是如何使用应用程序:

  1. 当您打开应用程序时,单击"绿色加号"按钮。将出现一个模式窗口。
  2. 在搜索框中输入"AAA",然后单击"搜索"。
  3. 将显示搜索结果。这就是问题所在。我想要的是,当用户单击"添加"按钮添加"问题"时,它应该关闭模态窗口并将"问题"添加到顶部文本区域中,但它没有这样做。

与输入不同,文本区域不使用 value 属性来存储数据,这可能就是 attr('value', 'bla') 失败的原因。

我相信 .val() 方法会自动考虑到这一点,因此无论如何都可以工作。

尝试类似操作:

var $questionText = $("<textarea class='textAreaQuestion'></textarea>").attr('name',$this.attr('name')+"[]").val($this.val());