0

アプリはhtmlダイブを受け取り、ページを作成してアプリに追加します

ページのセット内のすべてのリンク ボタンを、ページの ID に応じて異なるタスクを実行する 1 つの関数にバインドします。ページに複数のリンク ボタンがある場合に問題が発生します。クリックされたボタンの ID が必要です。

HTML:

<a id="x">x </a>
<a id="y">y </a>

J:

   var btns = [];
   $('#page-' + newpages[j].pageID + ' a').each(function () {
       btns.push({
           id: this.id,
           value: this.value,
           name: this.name
       });
   });
   for (i in btns) {

       $('#' + btns[i].id).bind('click', function () {
           test(btns[i].id)
       });
       // bin all buttons in current page to test()
   }
};
};

function test(x) {
   var page = $('.ui-page-active').attr('id');

   /////////
   //here I'm trying to ge the ID of clicked button of that page (each ID means something)
   var pos = '';
   $('#' + page + ' a').click(function () {
       //Get the id of this clicked item

       var BID = $(this).attr("id");
       alert(BID);
       send(BID);
   });
4

1 に答える 1

0

各ボタンのクリック イベントに個別にバインドしてみませんか? とにかくIDで切り替えると、一般的な関数を使用する理由があり、共有機能は関数に抽象化され、各クリックハンドラーで利用されるため、何も失うことはありません.

于 2013-02-27T13:38:58.877 に答える