0

私はphpを通してこのように呼び出すことができる作業中のjquery関数を持っています

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

前もって感謝します

OK、適切にリンクした 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();
}
4

1 に答える 1

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();
}
于 2013-02-27T11:36:11.297 に答える