在我的代碼中,我有一個用戶填充的HTML表單。然後,他們在「成員」字段中輸入一個值,然後單擊該按鈕以生成div ='sector_prop'的其他副本。 組成部分是 - 扇區數(LTE)使用for循環來追加div
<br>
<br>
<input type="text" id="member" name="member" value="">
<br>
<br>
<button>Generate Sector Properties</button>
這裏格 「sector_prop」 是
<div class="sector_prop">
<fieldset>
Primary LTE Carrier (Select lowest frequency on the site 850 for Band 5, AWS
for Band 4 and PCS for Band 2)<br>
<br>
<select name="lte_freq1">
<option value="6">850</option>
<option value="2">AWS</option>
<option value="4">PCS</option>
</select>
<br>
</fieldset>
我要追加使用for循環的股利。該代碼對於值1,2,3,4,5非常適用。當數值爲6或以上時,代碼會中斷並追加超過所需的div。我試圖找出爲什麼會發生這種情況。有什麼建議麼 ?
$(document).ready(function(){
$("button").click(function(){
var number = document.getElementById("member").value;
var repeat = $('.sector_prop');
var cloned = repeat.clone(true);
console.log(number);
for (i=1;i<number;i++){
cloned.appendTo('.sector_prop');
console.log(i);
console.log(cloned);
}
});
});
$(document).ready(function(){
$("button").click(function(){
var number = document.getElementById("member").value;
var repeat = $('.sector_prop');
var cloned = repeat.clone(true);
console.log(number);
\t for (i=1;i<number;i++){
cloned.appendTo('.sector_prop');
\t console.log(i);
\t console.log(cloned);
\t }
\t
});
});
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>
<form action="/form" method="post">
<fieldset>
<legend><b> Transport Information</b></legend>
<br>
<br>
OAM IP:<br>
<input type="text" name="oam_ip" pattern="^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$" required>
<br>
<br>
<fieldset>
<fieldset>
<legend><b> RF Parameters</b></legend>
<br>
Number of Sectors (LTE)<br>
<br>
<input type="text" id="member" name="member" value="">
<br>
<br>
<button>Generate Sector Properties</button>
<br>
<br>
<fieldset>
<div class="sector_prop">
<fieldset>
Primary LTE Carrier (Select lowest frequency on the site 850 for Band 5, AWS for Band 4 and PCS for Band 2)<br>
<br>
<select name="lte_freq1">
<option value="6">850</option>
<option value="2">AWS</option>
<option value="4">PCS</option>
</select>
<br>
<br>
</fieldset>
</div>
<input type="submit">
</form>
<br>
<br>
</body>
,你可以把它放在plunkr或使用該代碼段? –
也許'我'應該等於0? –