私は、WebページにjQueryとtablesorterプラグインを使用しています。私の目標は、メタデータインライン挿入機能を使用してクラスが空の各ヘッダーにtablesorterヘッダー無効化パーサを追加することです。私は3つの関数を説明しています。まず、空のクラス( "")を持つ各ヘッダーに無効パーサを追加するクラスです。2番目のクラスは空のクラスを持たないヘッダーに対してクラス切り替え操作を実行し、すべてのヘッダーが設定されると、実際のtablesorterが呼び出されます。私は最終的に最初の関数は、整理して、私は問題を得ることができたら、さらに第二の機能を拡張することを計画したがすべてのテーブルヘッダーにクラスを追加する
$(function(){
//Code is supposed to add the disable parser to each header with a blank class
$("th").each(function(){
if ($(this).hasClass('')){$(this).addClass('{sorter: 'false'}');
});
});
$(function() {
//Code manipulates headers with non-blank classes
});
$(function() {
//Call tablesorter on all tables once their headers are set.
$("table").tablesorter({});
});
は、これまで第二と第三の機能は、期待どおりに動作します。これは私の問題につながります。つまり、パーサーを追加する最初の関数はクラスを全く追加していないように見えますし、さらに正しく動作しないため、2番目と3番目が機能しないようです。これらの関数は、最初の関数を取り除くと機能します。私は構文が間違っているかどうか、あるいはパーサーをこのように動的に追加することができるかどうかはわかりません。以下は、HTMLからのヘッダーのサンプルです:
<th class=""><a rel = "Header" href="#" title="Sort title in decending order" class="">Title</a></th>
<th class=""><a rel = "Header" href="#" title="Sort instructor in descending order" class="">Instructor</a></th>
<th class="{sorter: 'usLongDate'}"><a rel = "Header" href="#" title="Sort column in decending order" class="">Date</a></th>
<th class="">Start/End</th>
<th class=""><a rel = "Header" href="#" title="Sort column in decending order" class="">Seats Available</a></th>
<th class=""><a rel = "Header" href="#" title="Sort column in decending order" class="">Enrolled</a></th>
<th class=""><a rel = "Header" href="#" title="Sort column in decending order" class="">Pre-Requisites</a></th>
<th class="">Workshop Actions</th>
それは働いたパオロ、ありがとう。それが働かないようにしていたのは、「偽」を取り巻く単一引用符がそこに存在するはずではないということでした。私はそれらを削除し、問題を修正しました。私はまだ非常に新しいjQueryなので、構文の便利なショートカットは高く評価されています。 – kingrichard2005