0

ここに記載されているjqueryダイアログページがあります:

<div data-role="page" data-rel="dialog" data-close-btn="none">
<div data-role="header">
<h2>Failed to find driver</h2>
</div>
<div data-role="content">
<p>Failed to find a driver. Would you like to continue searching or cancel the search?        </p>
<a data-role="button" id="continueBtn" onclick="alert('continue')">Continue </a>
<a data-role="button" id="cancelBtn" onclick="alert('cancel')">Cancel </a>
</div>
</div>

これらのアラートはダイアログで機能します。ただし、これらのボタンに他の機能のイベント ハンドラーをアタッチすることはできません。これらのボタンにイベントを添付するにはどうすればよいですか?

4

1 に答える 1

1

onclick="alert('cancel')"すでにjqueryを使用しているので、これをすでに実行しないでください..このように実行してください

$("#cancelBtn").click(function(){
    alert('cancel');
});

http://api.jquery.com/click/

コンテンツが動的にロードされる場合は、使用する必要がありますJquery.on()

 $("#cancelBtn")on.("click",function(){
        alert('cancel');
 });
于 2013-07-17T03:00:48.270 に答える