4

独特の問題。

スクリプトは「mousedown」で何かを実行し、「keypress」、「focusout」、「keyup」のいずれかのイベントで実行します。

問題は、そのうちの 1 つが実行されたら、残りの 2 つのイベントをどのように強制終了するかです。

、を試しましたが$(document).off()$(this).off('focusout')何も機能しません。

手がかりはありますか?

.on('mousedown', '.task-content', function() {
    // Make DIV Editable
})

.on('keypress', '.task-content', function (e) {
    if (e.which == 13 && !e.shiftKey) {
        // Update DIV content to DB
    }
})

.on('focusout', '.task-content', function() {
    // Update DIV content to DB
})

.on('keyup', '.task-content', function (e) {
    if (e.which == 27) {
    // Return DIV to previous state
  }
})
4

1 に答える 1

1

あなたのコードは正常に動作しています。間違っている可能性がありますselector

$('.task-content').on('keypress', function (e) {
    if (e.which == 13 && !e.shiftKey) {
        // Update DIV content to DB
        alert("key press");
        $(this).off('focusout');
    }
})

$('.task-content').on('focusout', function () {
    // Update DIV content to DB
    alert("focus out ");
})

このJSFiddleを確認してください。

于 2013-06-20T14:11:06.567 に答える