0

私はいくつかのクリックイベントハンドラーを次のように定義しました:

$(document).ready(function () {
  /*
  * Since the "Start Upload" button is available, we don't need to worry about starting the 
  * upload when the user clicks "Update". But we need to make sure to display an error message
  * if there are files in the uploader that have not been uploaded yet.
  */
  $('#myAccount p.buttons input[alt="Update"]').click(function (event) {

    // check if there are files in the uploader
    if (uploader.files.length > 0) {

        // if there are files that have not been uploaded yet, we need to show an error message
        if (uploader.total.uploaded != uploader.files.length) {

            // if the error message hasn't been created yet, create it
            // else, it'll already be visible so we don't need to do anything
            if ($('#upload_error').length == 0) {
                $('<p id="upload_error">Error!</p>').insertAfter('#myAccount p.buttons input[alt="Cancel"]');
            }
            event.preventDefault(); // stop the click event
        }
    }
    // continue click event as normal
  });
});

... と ...

// if the cancel button is clicked, then remove the files from the uploader
$('#myAccount p.buttons input[alt="Cancel"]').click(function (event) {
    uploader.splice(0, uploader.files.length);
    // continue click event as normal
});

どちらもFirefoxで正常に動作しますが、IE8とIE7(互換モード)では、これらは常に動作するわけではありません。

もう少し具体的に言うと、この「アップローダー」のものは、Pluploadファイルアップローダーに関連しています。基本的に、私はこのアップローダーをフォーム内に持っています。フォームは正常に送信され、アップローダーにまったく触れなければ、上記のクリックハンドラーは正常に機能します。

ただし、次の場合、上記のクリックハンドラーは機能しません。ファイルをキューに入れてアップローダーに処理を任せると、すべてのファイルがアップロードされます。フォームで[送信]をクリックしても何も起こりませんが、フォームが送信されることを期待しています。アップローダーを操作するときはいつでも、クリックイベントハンドラーが機能しません。

私のコメントが私の意図を明確にすることを願っています。これがIE7/8で機能しない理由について何かアイデアはありますか?私は何が間違っているのですか?event.preventDefault()IEでは処理が異なりますか?

ありがとう。

4

2 に答える 2

1

これを試して:

if (event.preventDefault) { event.preventDefault(); } else { event.returnValue = false; }

使用する前にpreventDefaultをテストしてください。

そうは言っても、jQueryを使用すれば、必要なのは1つだけreturn false;で、すべてを処理します。

于 2011-02-14T16:54:24.140 に答える
0

Flashランタイムに切り替えました。今のところ問題なく動作しているようです。

于 2011-02-16T07:15:26.253 に答える