これを繰り返しているのがわかります。jQueryでIDをフィルタリングして一致を捕らえる
$jq("button").filter(function(){
return this.id.match(/^user_(\d+)_edit$/);
}).click(function(){
var matches = this.id.match(/^user_(\d+)_edit$/);
var user_id = matches[1];
alert('click on user edit button with ID ' + user_id);
});
だから私はいくつかのボタンをクリックイベントを適用すると、クリックイベントハンドラで、私は、ユーザーIDが必要です。 2回目の試合を避ける方法はありますか?
$jq("button").filter(function(){
return this.id.match(/^user_(\d+)_edit$/);
}).click(function(){
var user_id = some_magic_variable;
alert('click on user edit button with ID ' + user_id);
});
ありがとうございます。
+1正規表現マッチングよりもかわいく、有用な提案です。 – karim79
私は 'edit_user'クラスの使用に同意しますが、各ボタンへのuser_idリンクが必要です。私はこれを行うことができますしかし、私はユーザーIDを取得するために一致する必要があります。 –
+1あなたをパオロにしてください...あなたは、2日か3日のあなたのものでした。洞察力の提供をやめてください! – Sampson