0

繰り返しますが、私はJQueryを初めて使用しますが、何らかの理由で、[シナリオの追加]ボタンをクリックしてもJQueryがフォームを追加しません。#add を含む関数にも到達していません。.on() 行にブレークポイントを設定しましたが、クリックしても認識されないようです。

$(document).ready(function ()
{
    $('#add').on('submit',function(e)
    {
        var form = "<div class='form'>\
        <h3> Scenario </h3>\
        <form id='scenario'>\
            <div>Name: <input type='text' name='ScenarioName'> </div>\
            <div>Rate of Investment Return (While Working): <input type='number' name='Working'></div>\
            <div>Rate of Investment Return (Retired): <input type='number' name='Retired'></div>\
            <div>Desired Retirement Yearly Income: <input type='number' name='desiredInc'></div>\
            <div><input type='submit' value='Submit'></div>\
        </form>\
        <div><button id='add' type='submit'>Add Scenario </button></div>\
    </div>"
        $('body').append($(form));
        e.preventDefault();
    });
});
<body>
    <div class='form'>
        <h3> Basic Information </h3>
        <form id='basic'>
            <div>Year of Birth: <input type='number' name='YOB'> </div> 
            <div>Current Savings: <input type='number' name='CurrSav'> 
            </div>  
            <div>Expected Retirement Age: <input type='number' name='RetAge'></div>     
            <div>Life expectancy: <input type='number' name='LifeExp'>
            </div>  
            <div><input type='submit' value='Submit'></div> 
        </form>
    </div>
    <div class='form'>
        <h3> Scenario </h3>
        <form id='scenario'>
            <div>Name: <input type='text' name='ScenarioName'> </div>
            <div>Rate of Investment Return (While Working): <input type='number' name='Working'></div>
            <div>Rate of Investment Return (Retired): <input type='number' name='Retired'></div>
            <div>Desired Retirement Yearly Income: <input type='number' name='desiredInc'></div>
            <div><input type='submit' value='Submit'></div>
        </form>
        <div><button id='add' type='submit'>Add Scenario </button></div>
    </div>
</body>
4

3 に答える 3