2

私のコードは次のとおりです

$(document).ready(function() {

    // this is a button to add the form to the DOM tree.
    $("#submitPara").click(function() {
        $("body").append('<form id = "dimensionAndObjects" action = "#"></form>');
        some code to add some input fields, omitted...
        $('#dimensionAndObjects').append('<p><input id = "submitDO" type = "submit" value = "submit"></input></p>');
        return true;
    });

    $('#dimensionAndObjects').submit(function() {
        alert("haahhhahhaha");
        return false;
    });

});

アラート情報が表示されないため、送信機能が動作していないようです。送信機能をクリック機能の中に入れても機能しません。どうしたの?私は jQuery の初心者です。よろしくお願いします。

4

2 に答える 2

4

フォームは動的に作成されるため、イベント委任を使用する必要があります

$(document).on('submit', '#dimensionAndObjects', function() {
        alert("haahhhahhaha");
        return false;
    });
于 2013-08-17T03:22:17.723 に答える
0
$('#dimensionAndObjects').live('click',function(e) {
e.preventdefault();
        alert("haahhhahhaha");
        return false;// for not submit the form
return true ;// for submit the form
    });
于 2013-08-17T06:35:44.877 に答える