代码之家  ›  专栏  ›  技术社区  ›  Kenny Lucero

Javascript-JQuery-Kendo-为什么要执行我的函数

  •  0
  • Kenny Lucero  · 技术社区  · 6 年前

    嗨,我对JS有点陌生,我想知道为什么我会有意外的行为。 我正在尝试定义一些函数并连接一些按钮,但页面加载时会触发一些事件,我无法确定它是否会触发,更重要的是,如何停止它。

    //this one does not execute on page load
    var saveDataCallback = function(){
        alert('Save Successful');
    };
    
    //this one executes on page load        
    var addFieldToForm = function(){
        alert('wtf mate');
    };
    
    
    $(document).ready(function(){
        //this one does not execute the alert when I load the page
        $("#showMePOTATOSALAD").on('click', function (){ alert(JSON.stringify(formDataObj)) });
    
        var dialog = $("#addToFormDialog");
        //this one does execute the dialog open when I load the page           
        $("#addToForm").on('click', function(){ dialog.data("kendoDialog").open() });
    }
    

    这就是问题所在

    dialog.kendoDialog({
        title:'Add Field to Form',
        modal:true,
        width: 500,
        height: 350,
        content:"",
        actions:[
            {text: 'Cancel'},
            {text: 'Add', action: addFieldToForm() }
        ]   
    });
    

    更改为

    dialog.kendoDialog({
        title:'Add Field to Form',
        modal:true,
        width: 500,
        height: 350,
        **visible: false,**
        content:"",
        actions:[
            {text: 'Cancel'},
            {text: 'Add', action: **addFieldToForm** }
        ]   
    });
    

    提前感谢

    2 回复  |  直到 6 年前
        1
  •  0
  •   Rushikumar Jeremy French    6 年前

    如评论中所述,您的 document ready 代码块缺少右括号。。。

    更改以下内容--

        $("#addToForm").on('click', function(){ dialog.data("kendoDialog").open() });
    }
    

    收件人:

        $("#addToForm").on('click', function(){ dialog.data("kendoDialog").open() });
    });
    
        2
  •  0
  •   jdtotow    6 年前
    $(document).ready(function(){
        //this one does not execute the alert when I load the page
        $("#showMePOTATOSALAD").on('click', function (){ alert(JSON.stringify(formDataObj)) });
    
        var dialog = $("#addToFormDialog");
        //this one does execute the dialog open when I load the page           
        $("#addToForm").on('click', function(){ dialog.data("kendoDialog").open() });
    }
    

    这很正常,单击ID为showMePOTATOSALAD的元素时会显示警报,单击ID为addToForm的元素时会显示对话框。