使用 PHP 从 HTML 表中获取 DATA-ID HTML
get data-id html from html table using php
我有一个使用 php 从 mysql 表生成的 html 表。有 ara 属性 html 使用数据 ex: data-id.但是为什么数据 ID 始终具有此表中第一行的值?这是 html
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th>No. </th>
<th>No Request</th>
<th>Username</th>
<th>Waktu Kirim Request</th>
<th>Keluhan</th>
<th>Status</th>
<th>Estimasi Penyelesaian</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr>
<td class="center">1. </td>
<td class="sorting1" id='no_request' data-id="002">TMS/IT/01/002</td>
<td class="center">Hud Aditywan</td>
<td class="center">25-01-2015, 21:04 </td>
<td class="center">Text One</td>
<td class="center"><a href="#" onclick="changeStatus();"><span class="label label-important">Done </span></a></td>
<td class="center">25-01-2015, 21:34 </td>
<td class="center">
<a class="btn btn-info" href="#">
<i class="halflings-icon white edit"></i>
</a>
<a class="btn btn-success" >
<i class="halflings-icon white print" id="print"></i>
</a>
</td>
</tr>
<tr>
<td class="center">2. </td>
<td class="sorting1" id='no_request' data-id="007">TMS/IT/01/007</td>
<td class="center">Hud Aditywan</td>
<td class="center">26-01-2015, 00:11 </td>
<td class="center">Another Text</td>
<td class="center"><a href="#" onclick="changeStatus();"><span class="label label-important">Not Yet </span></a></td>
<td class="center">26-01-2015, 00:41 </td>
<td class="center">
<a class="btn btn-info" href="#">
<i class="halflings-icon white edit"></i>
</a>
<a class="btn btn-success" >
<i class="halflings-icon white print" id="print"></i>
</a>
</td>
</tr>
</tbody>
我使用模式引导显示行的预览。
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h2>Confirm</h2>
</div>
<div class="modal-body">
<p id="id_preview"></p>
</div>
<div class="modal-footer">
<a href="#" id="btn-footer" class="btn btn-danger" onclick="executeStatus();">Ya</a>
<a href="#" class="btn" data-dismiss="modal">Tidak</a>
</div>
这是Jquery的代码:
function changeStatus() {
var x;
$('.label').click(function(e) {
e.preventDefault();
var $this = $(this);
var $trData = $this.closest('tr').clone();
$trData.find('td:last').remove();
var $thData = $this.closest('table').find('thead').clone();
$thData.find('th:last').remove();
var $table = $('<table border="2"></table>');
$table.append($thData).append($trData);
$("#id_preview").html($table);
$('#myModal').modal('show');
});
}
function executeStatus() {
$('#btn-footer').click(function(e) {
e.preventDefault();
var foo = $(".sorting1").data('id');
alert(foo);
});
}
我的问题是,为什么数据 id 总是有值 = 002 ?即使我有值 007 的行?
因为您总是在访问第一项
function executeStatus() {
$('#btn-footer').click(function(e) {
e.preventDefault();
var foo = $(".sorting1").data('id');
alert(foo);
});
}
您的函数从与".sorting1"匹配的第一项中获取数据 ID。您可能想尝试
$("#id_preview .sorting1").data('id')
相关文章:
- 无法将数据从firebase获取到我的html页面
- Brightcove获取/显示HTML中的当前视频标题和描述
- 获取HTML属性中CSS声明的值
- 这是使用html快照和谷歌获取的预期结果吗?SEO/SPA
- Html获取Rgb中的颜色
- 使用 jQuery 从 HTML 获取 id,给出意想不到的结果
- html获取调用onsubmit的位置
- 使用 HTML 获取已提交表单之外的选中元素
- 如何从 HTML 获取输入以链接到 MyChecker 函数?它不起作用
- 我如何从javascript到PHP或HTML获取变量
- 在ajax响应中从html获取输入值
- HTML获取URL参数
- ng-bind-html获取html内容的第一个字母
- 从HTML获取标题
- 从Html获取信息
- 使用Javascript和HTML获取选定的选项,并根据值显示字符串
- 通过AJAX和PHP通过输入HTML获取和读取文件
- 如何使用javascript生成的html获取标签的ID
- 在页面刷新(php)上从html获取表单数据
- JS Regexp:从 html 获取内联 JavaScript