以前にjQueryとJavascriptでいくつかのことを行ったことがありますが、残念ながら私は専門家ではありません. できるだけ少ないリソースを使用してタスクを達成する方法についてのヒントは見つかりませんでした。あなたたちはおそらく私を助けることができます:
これが私がやりたいことです:
次のようなページ上のすべての BB コードのような要素を (正規表現を使用して) 検索したい:
[ここのインデックス=パラメータのランダムデータ]
次に、それぞれを次のような ajax 呼び出しから受け取ったコンテンツに置き換えたいと思います。
call.php?index=here=パラメータ ランダムデータ
または、対応する [ndex] タグ内から取得したパラメーター。
これまでの私の解決策/思考プロセスは次のとおりです。
$(document).ready(function() {
var pattern = /\[ndex\s+(.*?)\]/mg;
var documentText = $(document.body).text();
var matches = documentText.match(pattern);
$('*').each(function () {
var searchText = this;
if ($(searchText).children().length == 0) {
$.each(matches, function() {
//here is where I would need to check for a match and make a call
}
});
}
});
});
ここからの働き方がよくわかりません。私のスケッチは本当にぎこちなくて複雑に思えます。よりエレガントで簡単なソリューションが必要です。
助けてくれてどうもありがとう。:)