开发者

How to set the focus to a textbox when a jquery dialog is loaded

When I am executing the below line, the dialog is opening properly.

$('#divMyDialogBox').dialog('open');

But I have a textbox (i.e txtAddr) inside the div (dialog box) & want the focus to be prompted, when it's going to be loaded.

I tried the below code but it's not working. Please rectify the same or suggest new solutions.

        $('#divEmailDialogBox').dialog
        ({
            modal: true,
            draggable: true,
            hide: 'slide',
            show: 'slide',
            height: 100,
            width: 575,
            bgiframe: true,
            autoOpen: false,
            resizable: false,
            closeOnEscape: false,
            zIndex: 9999,
            open: function(){alert("Hi"); $("#txtAddr").focus();}
        });

    <%if(true)
    {%>
               $('#d开发者_JS百科ivEmailDialogBox').dialog('open');
    <%}

Here alert is firing, indicates the code is getting called.

Thanks in Advance, Biki


Does your function get called at all? Does it get called before or after the dialog appears? (You can change the focus call with an alert to find out).

Have you tried using the dialog's focus event instead of the open event?


Best to make sure there is no other textbox on the page with the same ID. Can you paste your HTML here please?


Try to replace your current show with this:

show: { effect: 'slide', complete: function() { $(this).find("#txtaddr").focus(); }},

This should work for Jquery UI 1.8.4+

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜