如何将默认警报功能行为提供给qtip 2警报

时间:2013-04-05 12:38:09

标签: javascript qtip qtip2

我正在使用qtip2显示我的网络应用程序的提醒消息(如http://craigsworks.com/projects/qtip2/demos/#dialogues所示)

我的代码是

1)进行对话

function dialogue(content, title) {
    /* 
    * Since the dialogue isn't really a tooltip as such, we'll use a dummy
    * out-of-DOM element as our target instead of an actual element like document.body
    */
    $('<div />').qtip(
                {
                    content: {
                        text: content
                       , title: {
                           text: 'PMGSY ',
                           button: 'Close'
                       }
                    },
                    position: {
                        my: 'center', at: 'center', // Center it...
                        target: $(window) // ... in the window
                    },
                    show: {
                        ready: true, // Show it straight away
                        modal: {
                            on: true, // Make it modal (darken the rest of the page)...
                            blur: false, // ... but don't close the tooltip when clicked
                            escape: false
                        }
                    },
                    hide: false, // We'll hide it maunally so disable hide events

                    style: {
                        classes: 'qtip-shadow qtip-rounded qtip-dialogue', // Optional shadow...
                        widget: true //themeroller
                    },

                    events: {
                        // Hide the tooltip when any buttons in the dialogue are clicked
                        render: function (event, api) {
                            $('button', api.elements.content).click(api.hide);
                        },
                        // Destroy the tooltip once it's hidden as we no longer need it!
                        hide: function (event, api) { api.destroy(); }
                    }
                });
}

2)将其称为警报

function Alert(message) {
    // Content will consist of the message and an ok button
    var message = $('<p />', { text: message }),
    ok = $('<button />', { text: 'Ok', 'class': 'full' });
    dialogue(message.add(ok), 'Alert!');
}

问题是当我使用它时,它不会阻止进一步处理,直到用户点击确定按钮(如默认警报功能)。

例如,此警报甚至不显示。

Alert("Customised alerts"); //this doesent show      
window.location.replace("/Home/startPage");

如何使我的自定义警报模仿默认警报功能? 请帮忙

1 个答案:

答案 0 :(得分:0)

替换

ok = $('<button />', { text: 'Ok', 'class': 'full' });

ok = $('<button />', { text: 'Ok', 'class': 'full' }).click(function(){
    window.location.replace("/Home/startPage");
});