javascript – Jquery 1.9,JS – 函数未在Chrome中定义

这真让我感到困惑.我在main.js文件中定义了函数,它在头文件中加载,然后在我在HTML代码末尾调用函数.在Chrome中我收到错误未捕获的ReferenceError:未定义delete_image,但在Firefox中它正常工作(Opera中出现相同的错误).到底是怎么回事?

功能

function delete_image(button,data = false){
    button.on('click',function(){
    var $this = $(this),url = $(this).attr('href');

    if( data == 'tmp' )
    {
        data = 'id=' + $this.data('id');
    }
    else if ( data == true )
    {
        data = forma.serialize();
    }

    $.confirm({
        'title'     : 'Image Delete','message'   : 'Do you want to delete this image?','buttons'   : {
            'Yes'   : {
                'class' : 'blue','action': function(){
                    $.post(url,data,function(){
                        $this.parent().slideUp('slow');
                    });
                }
            },'No'    : {
                'class' : 'gray','action': function(){}
            }
        }
    });
    return false;
    });
};

调用函数(在HTML部分代码之后):

最佳答案
您今天无法在标准JavaScript中传递认参数值,这在Chrome中无效:

function delete_image(button,data = false){

你应该做的是

function delete_image(button,data){
    if (data == undefined) data=false;

MDN precises in what browsers you can use this feature(答案:仅限Firefox).

这应该与Harmony一起提供.这是some detail about ES6’s plan.

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: <span id=&quot...
jQuery 添加水印 <script src="../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...