1

次のようなデータを含むテーブルがあります。

<table>
 <tr onclick="window.location='download.php?id=1'">
  <td>Program 1<br/>Short Description 1 (<a onclick="$.popup.show('Install Instructions', 'Instructions pulled from DB here')">Instructions</a>)</td>
  <td>Added by user and date/time here<td>
  <td>Filesize here<td>
  <td><a href="edit.php?id=1">Edit</a> - <a href="delete.php?id=1">Delete</a><td>
 </tr>
 (repeat TRs for more programs pulled from DB)
</table>

私が抱えている問題は、(手順) リンクをクリックすると、手順を含むウィンドウがポップアップすることです。それは行いますが、TR の onclick も起動します。そのため、一瞬ポップアップが表示されてから、download.php に移動します。

TRのonclickを起動させないようにする方法はありますか? できればjqueryを使用しますが、プレーンなjavascriptソリューションも気にしません。

4

3 に答える 3

3

基本的に、 event.cancelBubble (IE の場合) または event.stopPropagation() (その他の場合) を使用して、イベントの伝播を停止する必要があります。quirksmode (私が以前に使用したもの)から得られる解決策は、次のようなことです。

<script type="text/javascript">
var instructions = function(e) {
    // Get the correct event in a cross-browser manner, then stop bubbling/propagation.
    if (!e) var e = window.event;
    e.cancelBubble = true;
    if (e.stopPropagation) e.stopPropagation();

    // Do what you want now
    $.popup.show('Install Instructions', 'Instructions pulled from DB here');
}
</script>

次に、スクリプトはそれを呼び出します:

<td>Program 1<br/>Short Description 1 (<a onclick="instructions(event)">Instructions</a>)</td>

(もちろん、これをすべてインライン化することもできますが、それはめちゃくちゃです。)

また、この質問に光を当てることもできます。

于 2009-05-04T15:43:40.787 に答える
0

stopPropogation はあなたが望むものです。

http://docs.jquery.com/Events/jQuery.Event#event.stopPropagation.28.29

于 2009-05-04T15:44:09.803 に答える
0

あなたは書ける

onclick="false"

イベント モデル レベル 2 を使用してイベントを追加します (ie では attachEvent、他のブラウザーでは addEventListener)。jquery を使用している場合は、jquery bind ('click') することもできます。

于 2009-05-04T15:50:01.863 に答える