使用jquery通过输入添加到表中
我一直在寻找答案。我可能没有使用正确的搜索条件,非常感谢您的帮助 我对编程很陌生。这可能是一个非常简单的解决方案。。。我似乎在网站上找不到它。现在,我正在努力获取一个两元素数组,在从用户获取输入后显示在表中。基本上是接受用户给出的两个数字,然后将它们放在表中的不同列中 在这一点上,我可以让他们进入表格,但是我不能让他们在每次添加新的行时都在自己的行中。它们只是被添加到同一行 非常感谢你的帮助 这是我的Java/Jquery使用jquery通过输入添加到表中,jquery,html,Jquery,Html,我一直在寻找答案。我可能没有使用正确的搜索条件,非常感谢您的帮助 我对编程很陌生。这可能是一个非常简单的解决方案。。。我似乎在网站上找不到它。现在,我正在努力获取一个两元素数组,在从用户获取输入后显示在表中。基本上是接受用户给出的两个数字,然后将它们放在表中的不同列中 在这一点上,我可以让他们进入表格,但是我不能让他们在每次添加新的行时都在自己的行中。它们只是被添加到同一行 非常感谢你的帮助 这是我的Java/Jquery // this one adds new data to the row
// 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.
//这一行将新数据添加到我创建的行中。
var$newTd=$(“”);
var$smallArrayPartOne=$(“”)。text($firstnumber);
var$smallArrayPartTwo=$(“”)。text($secondnumber);
//本节创建两个不同的数组
smallArray.push($firstnumber);
smallArray.push($secondnumber);
totalArray.push(smallArray);
//这是为了得到输入下的数字
打印=$(“”)。文本(总和);
$(“.totals”)。打印前;
//这将在我单击按钮后清除输入框
$(“.number输入”).val(“”);
$(“.other number input”).val(“”);
//这就是我将数组放入表中的方式。这让它正确地显示出来。但它并没有让html显示出我想要的效果。
$(“.theTable”).append($smallArrayPartOne);
$(“.theTable”).append($smallArrayPartTwo);
//我添加这个是因为当它不存在时,它会将数据添加到一行,而不是创建一个新的行。希望它能起作用。
还有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。。。
试试这个
$(".theTable").append($('<tr>').append($smallArrayPartOne));
$(“.theTable”).append($('').append($smallArrayPartOne));
一行是TR而不是TD。。。您的代码中没有新的TR。。。