我想查看按下按钮时在m警告框中检查的所有行但我在这里做错了
用于添加行的Javascript
$("#add").click(function () {
$("#myTable").last().append("<tr><td width='5%'><input type='checkbox'>
</td><td><input type='text' id='1stid'>
</td><td><input type='text' id='2ndid'></td><td><input type='text'id='3rdid'></td></tr>");
});
我也这样做但现在警报框是空的
$("#view").click(function () {
$('input[type="checkbox"]:checked');
var n=$(this).closest('tr').text();
alert(n);
});
我的HTML
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<link rel="stylesheet" href="Project.css">
</head>
<body>
<div class="container">
<button id="add">Add</button> <button id="deleteLast">Remove </button> <button id="delete"> Remove All</button> <button id="view">View</button>
<table class="table table-bordered" id="myTable">
<tr>
<th width="5%"></th>
<th>First name</th>
<th>Last name</th>
<th>Profession</th>
</tr>
</table>
</div>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="Project.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</body>
</html>
答案 0 :(得分:0)
由于 fatal error: mcrypt.h: No such file or directory
#include <mcrypt.h>
^
将返回数组/元素列表,因此请使用jQuery的$("input[type='checkbox']:checked")
方法,each
来迭代结果
$("input[type='checkbox']:checked").each(...)
&#13;
$("#view").click(function() {
$("input[type='checkbox']:checked").each(function(index) {
$('td input[type=text]', $(this).closest('tr')).each(function(index2) {
alert( $(this).val() );
});
});
});
&#13;