0

私のjsfiddleはここにあります-http ://jsfiddle.net/rDe9V/3/

関連するjQuery

$(function() {
    $('form input[type="text"]').live('keyup', function() {
        var val = $.trim(this.value);
        $('form .create-playlist-button').prop('disabled', val.length == 0)
    });
    $('form .create-playlist-button').click(function(e) {
        var title = $(e.target).closest('.video-detail').find('.title').text();
        alert(title);
    });
});   

要件

a。)[新規]をクリックすると、タイトル、ビューなどの対応するフォーム値を選択できるはずです。

b。)現在、キーを押すたびにアラートを出し続けます

私はjQueryを初めて使用しますが、よくわかりません

4

1 に答える 1

1

私のアップデートを見てください。

.live()と.click ()の代わりに.on()を使用しました。これは、ページ内の将来のすべての要素で機能するためです(liveただし、より良い)。また、フォームのイベントにハンドラー関数を追加しました。これsubmitは、[新規]ボタンをクリックするとトリガーされるためです(現在、これは体内のすべてのフォームに適用されるため、セレクターを絞り込むことができます。少し)。

そのハンドラーでは、必要なものをすべて取得し、.post()関数を使用してサーバーに送信できます。これがあなたの望むものだと思います。

以下の関連するコードを見つけてください。


$(document).ready(function() {
    // activate "New" buttons if input is not empty
    $('form input[type="text"]').live('keyup', function() {
        var val = $.trim(this.value);
        $(this).next("button").prop('disabled', val.length === 0);
    });

    $("body").on("submit","form",function(e){
        // do not submit the form
        e.preventDefault();

        // handle everything yourself
        var $form = $(this);
        var title = $form.closest('.video-detail').find('.title').text();
        var entryTitle = $form.find('.input-small').val();
        console.debug(title);
        console.debug(entryTitle);
        // send the data to the server using .ajax() or .post()
    });
});
于 2012-07-10T21:12:06.180 に答える