首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带param的调用函数

带param的调用函数
EN

Stack Overflow用户
提问于 2015-05-31 13:20:27
回答 1查看 55关注 0票数 0

我创建了这两个相互调用的函数,但是我不明白为什么不能调用函数ioFunction()。我做错什么了?

这样,我就可以调用这个函数:

代码语言:javascript
复制
$("[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);
            }
        }
    });
}   
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-05-31 13:51:48

我认为问题在于您的if声明:

代码语言:javascript
复制
if (b == "on" || c == "on" && d == "off") {

你的意思是:

代码语言:javascript
复制
if ((b == "on" || c == "on") && d == "off") {    

代码语言:javascript
复制
if (b == "on" || (c == "on" && d == "off")) {  

?考虑在您的条件周围加上括号,使其更加明确。

我敢打赌,如果您将一个断点/ console.log或其他东西放置在else中,您将永远不会到达它。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30557912

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档