对话框未加载正确的值 - JavaScript / Jquery

时间:2016-03-22 15:22:23

标签: javascript jquery html dialog modal-dialog

我有一个div,我有几个元素,如单选按钮,列表框等。 当用户点击一个按钮时,我们将该div放在一个对话框中并将其显示为弹出窗口。 这里的问题是,当我们为元素设置任何数据时(比如更改值或选中复选框) 它没有反映在弹出窗口中。

HTML CODE

<!--dialog -->
<div id="edit">
            <div id="dialog_contents">
            </div>
</div>

<div id="abc123">
lisbox...name="editListBox" id="editListBox"
checkbox..name="editCheckBox"  id="editCheckBox"
</div>

JS CODE

function edit()
{
        $("#editListBox" ).val('3');
        $("#editCheckBox").attr( 'checked', true );
        var data =  $("#abc123" ).html();
        $('#dialog_contents').html(data);
        $(edit).removeClass('hide').dialog('open');
}


    $('#edit').dialog({
            modal: true,
            draggable: true,
            resizable: false,
            autoOpen: false,
            width: 650,
            height: 750,
            cache: false,
            position:'center',
            open: function(event, ui) {

                window.setTimeout(function()
                        { jQuery(document) .unbind('mousedown.dialog-overlay') .unbind('mouseup.dialog-overlay') ; }, 100);
            },
            buttons: {
                "Cancel": function() {

                },
                "Edit": function() {
                    $( this ).dialog( "close" );

                }
            }               
        }); 

唯一的问题是,无论js函数中的设置值是什么,弹出窗口都没有反映出来。当我打印它们或在主屏幕上显示它时,它正确显示它们。

附加示例代码,忽略语法。

由于

1 个答案:

答案 0 :(得分:0)

I found the issue. In my case , when i add the existing div to another div. I'm having duplicate names,So when i tried to set values to those fields using name or id, its not giving me the element(may be because of ambiguity).

When i changed from id to class, the problem got resolved, i can find any element now and change its value.