0

我正在尝试使用 jquery 将动态添加到我的输入字段值中。但是传递的值不会附加到目标。我的代码如下所示

//on click popup modal with a form
    $(document).on('click', '#form', function(e) {
        e.preventDefault();         

        $('<div></div>').load($(this).attr('href')).dialog({
            title: $(this).attr('title'),
            //autoOpen: false,
            modal: true,            
            draggable: true,
            width:900,
            position: ['top',50], 
            close: function(event, ui) 
            { 
                $(this).dialog('destroy').remove()
            } 
        });
//this value should be appended to one of the input field, the value exists on alert but is not getting appended
        $('input#inputPrepend cashback').val( $(this).closest('tr').children('td.cashback').text() );

    });

笔记:

//this value is picked up from my Jquery Datatable clicked row
$(this).closest('tr').children('td.cashback').text()
//this input field is getting created inside of modal
$('input#inputPrepend cashback')

HTML

 <div class="formRow fluid">    
      <span class="grid12">
      <span class="grid2"><label class="form">Cashback</label></span>
      <span class="grid3">
        <div class="input-prepend">
           <span class="add-on">€&lt;/span>
              <input style="width:120px;height:30px; position relative; top:-10px"type="text"  id="inputPrepend cashback" type="text"  readonly="readonly" value="" />
        </div>
    </span>
    </span>            
    </div>
4

1 回答 1

1

在您的示例中:

$('input#inputPrepend cashback').val( $(this).closest('tr').children('td.cashback').text() );

$(this)指文档,而不是$('input#inputPrepend cashback')

您可以改用它:

var $input =  $('input#inputPrepend cashback');
$input.val( $input.closest('tr').children('td.cashback').text() );
于 2013-04-25T13:48:57.247 回答