1

Hey all i am trying to add a second button to this Apprise V2 JS code. However, i can not seem to get the correct click event for whichever one was clicked on.

Adding the buttons part of the code:

// Add buttons
$.each(settings.buttons, function(i, button) {

    if(button) {            
        button.id = "Accept";
        button.text = "Accept";

        var $_button = $('<button id="apprise-btn-' + button.id + '">').append(button.text);

        button.className = "green";
        $_button.addClass(button.className);
        $_buttons.append($_button);         
        $_button.on("click", function() {
            var response = {
                clicked: button,
            };

            button.action(response);
        });

        // Deny button
        button.id = "Deny";
        button.text = "Deny";

        var $_button = $('<button id="apprise-btn-' + button.id + '">').append(button.text);

        button.className = "red";
        $_button.addClass(button.className);
        $_buttons.append($_button);
        $_button.on("click", function() {
            var response = {
                clicked: button,
            };

            button.action(response);
        });
    }
});

And this is the part of the code that fires the box:

$(function() {  
    $('#custom-tryit').on("click", function() {     
        var $response = $('custom-response');       
        var options = { 
            buttons: { 
                confirm: {
                    text: 'Accept', 
                    className: 'blue', 
                    action: function(e) { 
                    console.log(this.id);

                        if (this.id == 'Deny') {
                            //Goto home page
                            console.log('home page');
                        } else {
                            //carry on
                            console.log('carry on');
                        }

                        Apprise('close'); 
                    }
                },
            },
            input: false
        };  

        Apprise('This is just a test here', options);
    });
});

The original code didn't seem to have an option for more than 1 button... The output seems to be outputting both values instead of just what was clicked on (console.log(this.id);):

Deny
home page 

Any help would be great!

The JSFIDDLE

4

1 回答 1

1

我修改了以下回复:

$_button.on("click", function() {
            var response = {
                clicked: button,
            };

$_button.on("click", function() {
            var response = {
                clicked: "Accept",
            };

并为拒绝按钮做了同样的事情。

然后在点击事件中

$('#custom-tryit')

我用了

if ( e.clicked == 'Deny') {

而不是this.id,它似乎工作正常。一探究竟:

http://jsfiddle.net/b2YZH/

于 2013-05-28T16:03:26.620 回答