无法调用基于参数的基于jquery的函数?

时间:2013-02-27 11:32:20

标签: javascript jquery jquery-ui function

我有一个工作的jquery函数,我可以通过php

这样调用
if (!order) 

        {   echo '<script>
$(function() {
$this = $("#ui-accordion-accordion-panel-0");
//  parent tab
var parent = $("#accordion").parent();
//parent.adderror();

// the content
$this.adderror();

// the header
var header = $this.attr("aria-labelledby");
$("#"+header).adderror();


// the tab
var tab = parent.attr("aria-labelledby");
$("#"+tab).parent().adderror();
});

    </script>';}

我想让它成为一个全局函数(如果在.js文件中外部定义,甚至更好)我可以在我的php中调用它,它将面板作为参数。

所以我基本上会打电话给 - show_error(“#ui-accordion-accordion-panel-0”)。我怎么能这样做?当我尝试定义函数,然后调用它时 - 没有任何改变。通过此处定义的技术使用无效(var functionName = function() {} vs function functionName() {}

提前致谢

好的,我现在有一个error.js文件,我已正确链接()

function show_error(selector) {
var $this = $(selector);

//  parent tab
var parent = $("#accordion").parent();

//parent.adderror();

// the content
$this.adderror();

// the header
var header = $this.attr("aria-labelledby");
$("#"+header).adderror();


// the tab
var tab = parent.attr("aria-labelledby");
$("#"+tab).parent().adderror();
}

1 个答案:

答案 0 :(得分:1)

外部.js文件中的函数如下所示:

function show_error(selector) {
    var $this = $(selector);
    //  parent tab
    var parent = $("#accordion").parent();
    //parent.adderror();

    // the content
    $this.adderror();

    // the header
    var header = $this.attr("aria-labelledby");
    $("#"+header).adderror();

    // the tab
    var tab = parent.attr("aria-labelledby");
    $("#"+tab).parent().adderror();
}