[英]When click table row alert that value
I want, when I click table row below function process.. I got output but when I double click then only show the result.. But I need single click result 我想要,当我单击函数过程下面的表格行时。.我得到了输出,但是当我双击时只显示结果。.但是我需要单击结果
Here my javascript: 这是我的JavaScript:
function found(row) { if (document.getElementById('ridee').checked) { var table=document.getElementById("table"); var rows = table.getElementsByTagName("tr"); for (var i = 0; i < rows.length; i++) { rows[i].onclick = (function() { // closure return function() { $('#loading').show(); var result = this.cells[1].textContent; var plate = this.cells[6].textContent; var km = this.cells[7].textContent; var dataString = 'plate=' + plate + '&km='+km + '&res='+result; $.ajax({ type: 'POST', url: 'km.php', async: true, data: dataString, cache: false, global: false, success: function(result) { $('#loading').hide(); var answer = confirm(result); if (answer == true) { return test(); } } }); } })(i); } } else { alert("You are rider... So, You can't select"); } }
I thought that return function is problem.. But without return function is not working.. Please anyone help 我以为返回函数是有问题的。。但是没有返回功能是行不通的。请任何人帮助
Thanks in advance.. 提前致谢..
This will be a lot easier if each functional component was split out. 如果每个功能组件都分开了,这将容易得多。
function getTableRows() {
var table = document.getElementById("table");
return table.getElementsByTagName("tr");
}
function buildDataStringFromRow(row) {
var result = row.cells[1].textContent;
var plate = row.cells[6].textContent;
var km = row.cells[7].textContent;
return 'plate=' + plate + '&km='+km + '&res='+result;
}
function postData(dataString, callback) {
$.ajax({
type: 'POST',
url: 'km.php',
async: true,
data: dataString,
cache: false,
global: false,
success: callback
});
}
function onRowClick() {
$('#loading').show();
var dataString = buildDataStringFromRow(this);
postData(dataString, function(result) {
$('#loading').hide();
var answer = confirm(result);
if (answer == true) {
return test();
}
}
}
function found(row) {
var tableRows = getTableRows();
if (document.getElementById('ridee').checked) {
for (var i = 0; i < tableRows.length; i++) {
tableRows[i].onclick = onRowClick.bind(tableRows[i]);
}
}
else {
alert("You are rider... So, You can't select");
}
}
Now that each function is very simple and easy to remove, now you may reason about which part is not working. 既然每个功能都非常简单且易于删除,那么您现在可以推断哪个部分不起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.