开发者

How to open jQuery modal dialog using <input type="button"> instead of anchor tag?

We previously have:

<input type='button' value='Some Button' onClick="window.open('somefile.php')">

Now we want to activate jQuery UI modal dialog instead of having a pop-up. We can trigger the modal dialog if we use an anchor tag like so: <a href="somefile.php" class="classfordialog">Open Dialog</a>.

But what if it's an input button?

I am using this script to call the dialog (and so that it can open a file into the dialog box):

$(document).ready(function() {
    $('.classfordialog').each(func开发者_如何转开发tion() {
        var $link = $(this);
        var $dialog = $('<div></div>')
            .load($link.attr('href') + ' #content')
            .dialog({
                autoOpen: false,
                title: $link.attr('title'),
                width: 500,
                height: 300
            });

        $link.click(function() {
            $dialog.dialog('open');

            return false;
        });
    });
});

Src: http://blog.nemikor.com/2009/04/18/loading-a-page-into-a-dialog/


You can use anything to activate the opening of the jQuery Dialog.

For example.

$(function(){
    $('.classfordialog').click(function(e){ e.preventDefault(); $('#dialog').dialog(); });
});

You can add the class to either a button, input, anchor, image, etc...


Well you obviously cant get the link and title from the "Link/A" if it isnt there?

    $(document).ready(function() {
        $('.classfordialog').each(function() {
            var $dialog = $('<div></div>')
                .load('somefile.php #content')
                .dialog({
                    autoOpen: false,
                    title: 'Some title',
                    width: 500,
                    height: 300
                });

            $('.inputdialog').click(function(e){ 
                e.preventDefault(); 
                $dialog.dialog('open');
            });
        });
    });
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜