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

Javascript 无法调用基于参数的jquery函数?,javascript,jquery,jquery-ui,function,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(); //

我有一个工作的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文件中的函数如下所示:

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();
}

我尝试了一些非常相似的方法,但没有成功。“我现在再试一次。@PratikBothra:好吧,还是有一个问题,那就是你从哪里得到
parent
。但从根本上说,这是可行的,除非您的问题中没有显示页面上的其他问题。为了帮助调试代码,我在函数中添加了一个警报($this),这就是我得到的-[object]作为警报。因此函数正在被调用,但目前没有发生任何变化。非常确定警报消息不应该显示,还是应该显示?@PratikBothra:it应该,
$this
是一个jQuery实例(对象),因为它是jQuery的
$
函数的返回值。这就是为什么你可以调用它的方法。alert(selector)给了我#ui-accordion-accordion-panel-0,如果这有帮助的话,你的函数会受到攻击,因为你没有声明你的
$this
变量?你还没有展示你从哪里得到的任何东西。我的错,我想我会发布这个片段。最后把你们弄糊涂了,对不起。刚刚做了相关的编辑。
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();
}