0
我一直在尋找,尋找一個答案。我可能沒有使用正確的搜索條件,並希望得到您的幫助。使用jQuery通過輸入添加到表
我對編程非常陌生。這可能是一個非常簡單的解決方案...我似乎無法在網站上找到它。現在我正在處理從用戶獲取輸入後獲取兩個元素數組以顯示在表中。基本上採用用戶給出的兩個數字,然後將它們放在表格的不同列中。
在這一點上,我可以讓他們在表上,但我不能讓他們給每個我添加新的時間在自己的行。他們只是被添加到同一行。
非常感謝您的幫助。
這裏是我的Java/jQuery的
// this one adds new data to the row that I create.
var $newTd = $("<td>");
var $smallArrayPartOne = $("<td>").text($firstnumber);
var $smallArrayPartTwo = $("<td>").text($secondnumber);
// This section creates my two different arrays
smallArray.push($firstnumber);
smallArray.push($secondnumber);
totalArray.push(smallArray);
// This is to get the numbers under the inputs
print = $("<p>").text(sum);
$(".totals").prepend(print);
// this clears the input boxes after I have clicked the button
$(".number-input input").val("");
$(".other-number input").val("");
// This is how I get the array in to the table. This gets it to show up right. It is not getting the html to show up how I would like it though.
$(".theTable").append($smallArrayPartOne);
$(".theTable").append($smallArrayPartTwo);
// I added this because when it was not there it would add data on to one row instead of creating a new one. Hopefully that gets it to work.
和HTML
<html>
<head>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<header>
</header>
<main>
<table style="width:50%" border="1" text-align="center" class = "theTable">
<tr>
<th>First Number</th>
<th>Second Number</th>
</tr>
<tr>
<td>Test number</td>
<td>Second Test</td>
</tr>
</table>
</br>
</br>
<section class="number-input">
<input type="integer">
</section>
</br>
</br>
<section class="other-number">
<input type="integer">
<button>+</button></br>
</br>
<section class="addition">
<button class="first">total number one</button>
<button class="second">total number two</button>
</section>
<section class="totals">
</section>
</main>
<footer>
</footer>
<script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
<script src="app.js"></script>
</body>
</html>
一排是TR不是TD ...你在你的代碼中沒有一個新的TR ... – Umingo 2015-03-08 19:22:17