【发布时间】:2016-05-26 23:26:49
【问题描述】:
我想在 html 表单中创建一个 html 表,其列数取决于用户将输入的变量。这是我很难工作的脚本的摘录。不幸的是,事实并非如此。
var nbrCofondateur = 5;
var nbrColonne = 2;
function tabGenerateur()
{
while (nbrCofondateur>nbrColonne) {
$("#col1").clone().appendTo("#col1").parent();
$("#col2").clone().appendTo("#col2").parent();
nbrColonne++;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container-fluid">
<h1>Calculatrice d'équité</h1>
<p>Remplissez ce formulaire pour déterminer quel pourcentage d'équité chacun des co-fondateurs de votre start-up devraient recevoir.</p>
</div>
<div class="container-fluid" class="deuximeFormulaire">
<form>
<table id="myTable">
<tr id="cofondateursListe" >
<th></th>
<th>Cf 1</th>
<th id="col1">Cf 2</th>
</tr>
<tr>
<td>Quel est le taux horaire que le co-fondateur pourrait exiger sur le marché du travail?</td>
<td><input style="width:100%" type="number" id="q1-cf1"></td>
<td id="col2"><input style="width:100%" type="number" id="q1-cf2"></td>
</tr>
</table>
<button type="submit" class="Submit" onclick="tabGenerateur();">Soummettre</button>
</form>
</div>
【问题讨论】:
-
请澄清您的具体问题或添加其他详细信息以准确突出您的需要。正如目前所写的那样,很难准确地说出你在问什么。
-
我可能明白你想要什么。您不必将
parent()放在append()之后,而且您不应拥有多个具有相同ID 的元素,这正是您通过复制元素所做的事情。 -
@ZakariaAcharki,标题还不够清楚吗?
-
您的代码不够清晰,无法反映您在标题中的内容。
标签: javascript jquery html html-table