简体   繁体   中英

Call Function with param

I created these two functions that call each other but I can not see why I can not call the function ioFunction(). what can I be doing wrong?

This way I get to call the function:

$("[name=flip-4]").change(function() {
    var b = $("#flip-2").val();
    var c = $("#flip-3").val();
    var d = $("#flip-4").val(); 

    if (b == "on" || c == "on" && d == "off") {
        var message = 'the roof cant be close when some setups is on.';

        dialogFunction(message);

        $("#flip-4").val("on");                    
    } else {
        var message = 'the roof will be ' + d + ': ' + output + '.';                                   
        var flip = 'flip4';

        ioFunction(flip,d,message);
    }
});

function dialogFunction(param) {
    var html = '<div data-role="dialog" id="page2" data-mini="true" data-close-btn="right">';
    html += '<div data-role="header"><h1 style="text-align:left; margin-left:10px;">Atention</h1></div>';
    html += '     <div role="main" class="ui-content">';
    html += '          <legend>' + param +'</legend>  ';
    html += '     </div>';
    html += '     </div>';

    $('#page2').remove();
    $('body').append(html);
    $('#page2').enhanceWithin();

    $.mobile.changePage("#page2");
}

function ioFunction(parama,paramb,paramc) {
    $.ajax({
        url: 'io.php?'+ parama + '=' + paramb,
        dataType: 'text',
        success: function(output){
            var output = $.trim(output);
            if (output == "success") {
                dialogFunction(paramc);
            } else {
                dialogFunction('ERROR: ' + output);
            }
        }
    });
}   

I think the problem lies in your if statement:

if (b == "on" || c == "on" && d == "off") {

Do you mean:

if ((b == "on" || c == "on") && d == "off") {    

or

if (b == "on" || (c == "on" && d == "off")) {  

? Think about putting parentheses around your conditions to make it more explicit.

I'm willing to bet that if you put a breakpoint / console.log or something inside the else , you would never reach it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM