使用jQuery Zebra Dialog单击注销链接时如何执行代码?

时间:2014-01-15 16:25:19

标签: javascript jquery

如何将这种代码放在注销导航链接代码中?我刚接触到jquery所以我有麻烦......我需要你的帮助。

这是我需要的代码:

<a href="#">Logout</a>

继承人代码:

<script type="text/javascript"  src="Zebra_Dialog-master/public/javascript/zebra_dialog.js"></script>
<link rel="stylesheet" href="Zebra_Dialog-master/public/css/default/zebra_dialog.css" type="text/css">

<script>
$.Zebra_Dialog('<strong>Do you want to Logout?</strong>', {
    'type':     'question',
    'title':    'Non-uniformed Personnel (NUP)',
    'buttons':  [
                    {caption: 'Yes', callback: function() { alert('"Yes" was clicked')}},
                    {caption: 'No', callback: function() { alert('"No" was clicked')}},
                    {caption: 'Cancel', callback: function() { alert('"Cancel" was clicked')}}
                ]
});
</script>

4 个答案:

答案 0 :(得分:2)

您可以使用.click()处理程序

HTML

<a id="logout" href="#">Logout</a>

的JavaScript

$(document).ready(function() {
    // show a dialog box when clicking on a link
    $("#logout").on('click', function(e) {
        e.preventDefault();
        $.Zebra_Dialog('<strong>Do you want to Logout?</strong>', {
            'type':     'question',
            'title':    'Non-uniformed Personnel (NUP)',
            'buttons':  [
                            {caption: 'Yes', callback: function() { alert('"Yes" was clicked')}},
                            {caption: 'No', callback: function() { alert('"No" was clicked')}},
                            {caption: 'Cancel', callback: function() { alert('"Cancel" was clicked')}}
                        ]
        });
    });
 });

答案 1 :(得分:0)

<a href="#" id="logout_button">Logout</a>

和Javascript:

$('#logout_button').click(function(){
    //whatever you want to happen when you click the button goes here
})

答案 2 :(得分:0)

来自http://stefangabos.ro/jquery/zebra-dialog/

>$(document).ready(function() {

// show a dialog box when clicking on a link
$(anchor).bind('click', function(e) {
    e.preventDefault();
    $.Zebra_Dialog('The link was clicked!');
});

});

为您的代码添加ID,

<a href='#' id='logout'>logout</a>

在上面的代码中用'#logout'替换'anchor'。

答案 3 :(得分:0)

您应该将一个点击处理程序附加到您的注销链接。

如果您创建一个id(或者如果您在整个页面中分散了多个注销选项,则为一个类),这是微不足道的。

<a id="logout" href="#">Logout</a>

然后在初始化代码中:

$("#logout").click(
  $.Zebra_Dialog('<strong>Do you want to Logout?</strong>', {
    'type':     'question',
    'title':    'Non-uniformed Personnel (NUP)',
    'buttons':  [
                {caption: 'Yes', callback: function() { alert('"Yes" was clicked')}},
                {caption: 'No', callback: function() { alert('"No" was clicked')}},
                {caption: 'Cancel', callback: function() { alert('"Cancel" was clicked')}}
            ]
  });
);