你好,我有这张table
<script type="text/javascript">
function rldashboard () {
document.getElementById('livetableops').innerHTML = "";
$(document).ready(function(){
$.ajax({
url: "getsomedata.php",
method: "GET",
success: function(livedb) {
var livetabledasboard = '';
for (var i = 0; i < livedb.length; i++) {
livetabledasboard += '<thead align="center" style="display: none;">';
livetabledasboard += '<tr>';
livetabledasboard += '<th>ID</th>';
livetabledasboard += '<th>Time</th>';
livetabledasboard += '<th>Country</th>';
livetabledasboard += '<th>Type</th>';
livetabledasboard += '<th>Amount</th>';
livetabledasboard += '<th>Coin</th>';
livetabledasboard += '<th>Price USD</th>';
livetabledasboard += '<th>Action</th>';
livetabledasboard += '</tr>';
livetabledasboard += '</thead>';
livetabledasboard += '<tr>';
livetabledasboard += '<td align="center" class="rlidzoom">' +
livedb[i].data.id +
'</td>';
livetabledasboard += '<td align="center" width="200" >' +
livedb[i].data.hora +
'</td>';
livetabledasboard += '<td align="center">' +
livedb[i].data.country +
'</td>';
livetabledasboard += '<td align="center">' +
livedb[i].data.status +
'</td>';
livetabledasboard += '<td align="center">' +
livedb[i].data.cantidad +
'</td>';
livetabledasboard += '<td align="center">' +
livedb[i].data.moneda +
'</td>';
livetabledasboard += '<td align="center">' +
livedb[i].data.total_dolares +
'</td>';
livetabledasboard += '<td align="center">' + ' <button type="button" class="btn btn-primary" onclick="getidnow();" >Review</button> '+
'</td>';
livetabledasboard += '</tr>';
}
$('#livetableops').append(livetabledasboard);
colorboard();
}
})
console.log('LIVE-BOARD');
})
}
这个表是由另一个按钮生成的调用该函数(rldashboard)我想要的是,当用户单击行时,我得到变量中第一个单元格的值,我可以发送给post,现在我已经开始工作了,但是有一个我似乎没有发现的错误,我已经成功地使用以下代码获得了我需要的值:
$('td').click(
function(){
horizSize = $(this).prevAll('td:last').text();
alert(horizSize);
});
}
另外一个也可以:
$("#livetableops").on("click", "td", function(){
var idoperacion = $(this).parent("tr").find("td:first").text();
console.log(idoperacion);
问题是,当用户第一次单击按钮时,它会在单击通过并检索数据后检索提交行的正确id号,用户第二次按任何其他行中的review按钮时,它通过获取id的编号来工作,并显示正确的数据,但如果再次单击,提交将加倍,它将变为4,n,n,6等等。如何解决此问题?我还尝试在显示数据后清除变量内容,但变量仍然像每次单击表一样以指数方式累积和重新提交。
浏览器控制台中的示例如下所示
this is like accumulative submission that im trying to prevent ->(3).php:3110 161 ->this is the id number retrieved
this is like accumulative submission that im trying to prevent ->(4)xxx.php:3110 162 -->this is the id number retrieved
我目前使用的完整功能有以下缺陷:
<script>
function getidnow() {
$("#livetableops").on("click", "td", function(e){
e.preventDefault();
var idoperacion = $(this).parent("tr").find("td:first").text();
console.log(idoperacion);
var email = "<?php echo $email_login ?>";
$.ajax({
url: './modaloffer.php',
type: 'POST',
data: { email: email, idoperacion: idoperacion },
cache: false,
success: function(data) {
$('#resultsquerybopard').html(data);
}
});
});
}
</script>
谢谢,谢谢你的帮助
暂无答案!
目前还没有任何答案,快来回答吧!