【问题标题】:syntax problems with my script我的脚本有语法问题
【发布时间】:2013-09-12 21:34:28
【问题描述】:

这是原始脚本...

$j(document).ready(function() { 
    //Show and hide the Loading icon on Ajax start/end

    $j('.bwbps_uploadform').submit(function() { 
        $j('#bwbps_message').html('');
        bwbpsAjaxLoadImage(this);
        return false; 
    });

    //make sure the upload form radio button is on Select file
    $j(".init_radio").attr("checked","checked");
        //Add OnClick to the Mass Update Buttons in the PhotoSmash Settings form
        if ($j('#bwbps_gen_settingsform').val() == '1') {
            bwbpsAddPSSettingsMassUpdateActions();
        }
        $j('.bwbps-post-cat-form').attr('multiple','multiple');
    }   
});

我想改变这个脚本在另一个函数中调用它,但是firebug中有语法错误:

var myFunction;
$j(document).ready(function() { 
    //Show and hide the Loading icon on Ajax start/end
    myFunction = function() {
        $j('.bwbps_uploadform').submit(function() { 
            $j('#bwbps_message').html('');
            bwbpsAjaxLoadImage(this);
            return false; 
        });

        //make sure the upload form radio button is on Select file
        $j(".init_radio").attr("checked","checked");

        //Add OnClick to the Mass Update Buttons in the PhotoSmash Settings form
        if ($j('#bwbps_gen_settingsform').val() == '1') {
            bwbpsAddPSSettingsMassUpdateActions();
        }
        $j('.bwbps-post-cat-form').attr('multiple','multiple');
    }   
});

怎么了?有谁能够帮我??

var $j = jQuery.noConflict();

感谢您的帮助!

【问题讨论】:

  • 应该是var j = $j = jQuery.noConflict();
  • Firebug 给你的错误是什么
  • 这不是问题^^在代码中:var $j = jQuery.noConflict();
  • 我不认为这可能是问题,但你错过了函数闭包的分号。

标签: jquery syntax


【解决方案1】:

这样使用:

 var myFunction;
 $j(document).ready(function() { 
  //Show and hide the Loading icon on Ajax start/end
  myFunction = function($j) {
    $j('.bwbps_uploadform').submit(function() { 
        $j('#bwbps_message').html('');
        bwbpsAjaxLoadImage(this);
        return false; 
    });

    //make sure the upload form radio button is on Select file
    $j(".init_radio").attr("checked","checked");

    //Add OnClick to the Mass Update Buttons in the PhotoSmash Settings form
    if ($j('#bwbps_gen_settingsform').val() == '1') {
        bwbpsAddPSSettingsMassUpdateActions();
    }
    $j('.bwbps-post-cat-form').attr('multiple','multiple');
   }   
 });

在 myFunction 中传递 $j 作为参数

【讨论】:

  • 我唯一想要的是我可以在另一个函数中调用这个函数......或者也许有更简单更好的解决方案?
猜你喜欢
  • 1970-01-01
  • 2014-11-10
  • 2013-03-11
  • 2020-10-29
  • 2012-05-31
  • 1970-01-01
  • 2011-07-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多