我有一個工作的jquery功能,我可以通過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」)。我怎麼能這樣做?當我嘗試定義函數,然後調用它時 - 沒有任何變化。通過使用這裏定義無濟於事techinques爲(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();
}
FWIW,你的函數的獵物下降到[*隱全局*的恐怖(http://blog.niftysnippets.org/2008/03/horror-的隱-globals.html),因爲你沒有聲明你的'$ this'變量。 – 2013-02-27 11:37:26
行中的'parent' var tab = parent.attr(「aria-labelledby」);'?你沒有顯示任何東西顯示你在哪裏得到。 – 2013-02-27 11:38:53
我的不好,以爲我只是張貼片段。結束了你所有的困惑,我很抱歉。剛剛做了相關的編輯。 – 2013-02-27 11:43:06