gpt4 book ai didi

jquery - Bootstrap 向表中添加行

转载 作者:行者123 更新时间:2023-11-28 04:19:45 25 4
gpt4 key购买 nike

我正在尝试向我的表中动态添加行。出于某种原因,当我向表中添加一行时,它全部被揉成一团,并且没有跨越整行。为什么会发生这种情况,我该如何解决?

这里是我的文件,如果你想运行它看看我的意思

jQuery:

$(document).ready(function () {

$('.close').on('click', function (e) {
e.preventDefault();
$(this).parent().parent().remove();
});

$('#submit').click(function () {
var name = $('input[name=name]').val();
var phone = $('input[name=phone]').val();
var email = $('input[name=email]').val();


var tr = "<tr>\
<td>\
<a href=\"#" + name + "openModal\">" + name + " </a>\
\
<div id=\"" + name + "openModal\" class=\"modalDialog\">\
<div>\
<a href=\"#close\" title=\"Close\" class=\"close\">X</a>\
<h2> " + name + "</h2>\
><p>Phone: " + phone + "</p>\
<p>email: " + email + "</p>\
</div>\
</div>\
</td>\
<td> \
<input type='radio' name=\"" + name + "present\">In<br>\
<input type='radio' name=\"" + name + "present\">Out\
</td>\
<td>\
<button type=\"button\" class=\"close\"><span aria-hidden=\"true\">&times;</span><span class=\"sr-only\">Close</span></button>\
<textarea placeholder=\"Optional Note about where your are or your schedule\"></textarea>\
</td>\
</tr>;";
$('#table').append(tr);

$("input[type=text]").val("");
$("input[type=tel]").val("");
$("input[type=email]").val("");

});
});



还有我的 HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>iSignout</title>

<link type="text/css" rel="stylesheet" href="bootstrapCSS.css"/>
<link href="css/bootstrap.min.css" rel="stylesheet"

</head>
<body>

<div id="left">
<h3 id=add>Add An Employee</h3>
<form class="input">
Name: <input type="text" name="name"><br>
Phone Number: <input type="tel" name="phone"><br>
E-Mail: <input type="email" name="email"><br>
<input type="button" value="Add" id="submit" />
</form>
</div>

<!--Creates the tables with employees -->
<div id='table'>
<table class= 'table table-hover'>
<thead>
<tr id="title"><th colspan=3>People In the Office</th></tr>
</thead>

<tbody>
<!--Create rows here -->
<tr>
<th>Name</th>
<th class>IN/OUT Status</th>
<th>Optional Note</th>
</tr>

<tr>
<td>
<a href="#openModal">Peter Griffin</a>

<div id="openModal" class="modalDialog">
<div>
<a href="#close" title="Close" class="close">X</a>
<h2>Peter Griffin</h2>
<p>Phone:123-456-7890.</p>
<p>email: petergriffin@gmail.com</p>
</div>
</div>
</td>
<td>
<input type='radio' name="Peterpresent">In<br>
<input type='radio' name="Peterpresent">Out
</td>
<td>
<button type="button" class="close"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
<textarea placeholder="Optional Note about where your are or your schedule"></textarea>
</td>
</tr>

</tbody>
</table>
</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="bootstrap_script.js"></script>

</body>
</html>

http://jsfiddle.net/36Qzy/

最佳答案

您将新表格行直接附加到您的 <div> 中- ID 为 table 的那个.相反,你应该附加它,可能在你的 <tbody> 的末尾.您可以使用 descendant selector为了这;更改您的 append(tr)在你的 $('#submit').click() 行以下处理程序:

$('#table tbody').append(tr);

关于jquery - Bootstrap 向表中添加行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24615850/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com