jquery ui dialog: possible to create a list element on close?

When I close the dialog, I want a list element to be made on the fly. When the list element is clicked, the dialog is opened again. Is this possible?

$('#dialog').dialog({
    close: function() {
        var e = $(this).parent().find('.ui-dialog-title').text();
    var id = $(this).attr("id");

    $('li',
        {
        class: id,
        value: e,
        click: function(){
        $('#'+id).dialog('open');
            }
    }).appendTo('#aULelement');
    },
    open: function() {
        var id = $(this).attr("id");
        if ($('.'+id).length){
            $('.'+id).remove();
        }
    }
});

As of now, this code does not build a list item but returns no error.


You were close. You need to use <li/> and text or html instead of value :

$('#dialog').dialog({
    close: function() {
        var e = $(this).parent().find('.ui-dialog-title').text();
        var id = $(this).attr("id");
        $('<li/>', {
            class: id,
            text: e,
            click: function() {
                $('#' + id).dialog('open');
            }
        }).appendTo('#aULelement');
    },
    open: function() {
        var id = $(this).attr("id");
        if ($('.' + id).length) {
            $('.' + id).remove();
        }
    }
});

Example:

http://jsfiddle.net/jtbowden/BGLxW/

链接地址: http://www.djcxy.com/p/80904.html

上一篇: mouseleave时停止mouseenter动画

下一篇: jQuery的用户界面对话框:可以创建关闭列表元素?