passing parameters to jquery ui dialog

2019-04-29 09:08发布

I use .data like this to pass the id of the textbox that calls the dialog

$("#<%=txtDirProprio.ClientID%>").focus(function() 
{
         $("#<%=dialog.ClientID%>").dialog( "open" ).data("id","#<%=txtDirProprio.ClientID%>");
         return false;
});

here is the code for the dialog

 $("#<%=dialog.ClientID%>").dialog({
                autoOpen: false,
                show: "blind",
                hide: "explode",
                width: 800,
                height:200,
                modal: true,
                buttons: 
                {
                    "Ajouter": function() {
                        $( this ).dialog( "close" );
                        StringBuilderDir($( this ).data("id"));
                    },
                    "Vider": function() {
                        $( this ).dialog( "close" );
                        $( $( this ).data("id") ).val("")
                    },
                    "Canceler": function() {
                        $( this ).dialog( "close" );
                    }
                },
                open: function() 
                { 
                    var dir = $( $( this ).data("id") ).val().split("-");
                    if(dir[0] != "")
                    {
                        $("#<%=dd_dialog_directionvp.ClientID%> option").each(function(index) 
                        {
                            if ($("#<%=dd_dialog_directionvp.ClientID()%> option")[index].text == dir[0]) 
                            {
                                $("#<%=dd_dialog_directionvp.ClientID()%>  option")[index].selected = true;
                            }
                        })
                     }
                 }
                 });

So $ ( this ).data("id") returns the id of the textbox. It works fine except in the open function. The id is undefined

Why it works in the functions for the buttons but not in the open function. It looks like it's not the same 'this'

Thank you

1条回答
仙女界的扛把子
2楼-- · 2019-04-29 09:47
$("#<%=txtDirProprio.ClientID%>").focus(function() 
{
         $("#<%=dialog.ClientID%>").data("id","#<%=txtDirProprio.ClientID%>").dialog( "open" );
         return false;
});

Have to set the data first before calling .dialog('open');

查看更多
登录 后发表回答