入力ボックスと送信ボタンを備えたフォームを動的に作成しようとしています。作成されるボックスの数は、選択メニューで選択した数です。問題は、フォームで動的に作成されたボタンをクリックするたびに Go to Step 3 と呼ばれ、ダイアログに移動せず、その理由がわからないことです。どんな助けでも本当に感謝します。これが私のコードです:
<div id ="steptwo" data-role="page" data-theme="a">
<div data-role ="header">
<h1> </h1>
</div>
<div data-role = "content">
<center>
<p>This is step two of four. We require at this stage information about the cars you drive for our new system. Please select the number of cars you own in the list below:</p>
<select id="carcount">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
<div id="NumberOfCars">
</div>
</center>
</div>
</div>
<div id ="diaglogchildren" data-role="dialog" data-theme="a">
<div data-role="header">
<h3>Do you have any children?</h3>
</div>
<div data-role = "content">
<center>
<input type="submit" id ="ChildrenYes" name="ChildrenYes" value="Yes" data-theme="a">
<br>
<input type="submit" id ="ChildrenNo" name="ChildrenNo" value="No" data-theme="a">
</center>
</div>
</div>
私のJavaScript:
$(document).on("pageinit","#steptwo",
function()
{
$("#carcount").change(function()
{
$("#NumberOfCars").empty();
var stringbuild = '';
for (var i = 0; i < $("#carcount").val(); i++)
{
stringbuild = stringbuild + '<input type="text" id="car' + i + '" name="carmake" placeholder="Please enter Vehicle ' + (i+1) + ' Make"><input type="text" id="car' + i + '" name="carreg" placeholder="Please enter Vehicle ' + (i+1) + ' Registration Number">';
};
stringbuild = '<form name="CarOnwerDetails" action="#" method="post">' + stringbuild + '<input type="submit" id="CarSubmit" name="CarSubmit" value="Go to Step 3" data-theme="a"></form>';
alert(stringbuild);
$("#NumberOfCars").append(stringbuild).trigger("create");
});
$("#CarSubmit").click(function(e)
{
e.preventDefault();
window.location.href = "#diaglogchildren";
});
});