Jquery - 向对话框字段添加值

时间:2013-01-12 05:19:45

标签: javascript jquery jquery-ui

我正在尝试将值从某个行复制到我使用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>

表格:                                                             

1 个答案:

答案 0 :(得分:0)

啊,我只想出来了。这条线有效:

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

我的问题是我忘记了班级名称之前的一段时间。它应该是:

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