0

在用户单击“添加”按钮后,我试图将一些内容添加到文本区域中,但没有任何反应。有什么我想念的吗?

以下是添加所选内容的 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. 显示您的搜索结果。这就是问题所在。我想要的是,当用户单击“添加”按钮添加“问题”时,它应该关闭模式窗口并将“问题”添加到顶部文本区域,但它没有这样做。
4

1 回答 1

0

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

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

尝试类似:

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

于 2012-05-30T09:42:35.377 回答