0

我正在尝试将某行中的值复制到我使用 jquery 调用的对话框表单中,但无法使其正常工作。(编辑功能)。对话框打开,但没有传递来自 ei_Ingredient 的值。上述“添加成分”功能完美运行。下面是我的代码,你可以看到我迄今为止尝试过的三种方法......

    $(document).ready(function () {

        var _Ingredient = $('#ingHeader'),
            _newIngredient = $('#newIngredient'),
            _newMeasurement = $('#newMeasurement'),
            _newAmount = $('#newAmount'),
            allFields = $([]).add(_newIngredient).add(_newMeasurement).add(_newAmount)
        $('#dialog-form').dialog({
            autoOpen: false,
            height: 300,
            width: 350,
            modal: true,
            show: "clip",
            hide: "scale",
            speed: "fast",
            buttons: {
                "Add Ingredient": function () {
                    var _row = $('#templates').find('.row-template-ExistingItem').clone();
                    _row.find('.ei_Ingredient').val(_newIngredient.val());
                    _row.find('.ei_Measurement').val(_newMeasurement.val());
                    _row.find('.ei_Amount').val(_newAmount.val());
                    _row.find('.edit').click(function () {
                        _newIngredient.val();
                        _newMeasurement.val(_row.find('ei_Ingredient').val());
                        _newAmount.val($('.ei_Amount').val());
                        $('#dialog-form').dialog('open');
                    });
                    _row.find('.delete').click(function () {
                        _row.remove();
                    });

                    _Ingredient.append(_row);
                    $(this).dialog("close");
                },
                Cancel: function () {
                    $(this).dialog("close");
                }
            },
                close: function () {
                    allFields.val("");
                }
        });

模板:

    <tr class="row-template-ExistingItem">
        <td><input class="ei_Ingredient"  readonly="true"/></td>
        <td><input class="ei_Measurement"  readonly="true" /></td>
        <td><input class="ei_Amount" readonly="true" /></td>
        <td><input type="button" value="Edit" class="edit" style="width:45px;" /></td>
        <td><input type="button" value="Delete" class="delete" style="width:45px;" /></td>
    </tr>

表格:

4

1 回答 1

0

啊,我刚想通了。这是行之有效的:

_newMeasurement.val(_row.find('ei_Ingredient').val());

我的问题是我忘记了班级名称前的句号。它应该是:

_newMeasurement.val(_row.find('.ei_Ingredient').val());
于 2013-01-13T04:57:04.383 回答