因此,再次,我是 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>