[英]How to get Table data values as variables using javascript
i have a page on the browser that displays some items in a table format. 我在浏览器上有一个页面,该页面以表格格式显示一些项目。 now i want to select particular items (rows) and then get the data (columns values) of those selected rows as variables in a Javascript function so i can use them as parameters in a query string on an ASP page. 现在,我想选择特定的项目(行),然后将那些选定行的数据(列值)作为Javascript函数中的变量获取,因此我可以将它们用作ASP页上的查询字符串中的参数。
function selectedRows()
{
var selectedItems = Hesto.UI.GetSelectedItems('#ScannedLabelTable');
$.each(selectedItems, function (i, item) {
$.ajax({
url: PRINT_LABELS_QUERY_PAGE
, data: // this is where i need help on..
, dataType: 'json'
, success:alert("Labels Printed")
, error: Hesto.Ajax.ErrorHandler
});
});
FetchLabelDetails();
}
From a table like this you can accept using document.getElementById("").innerHTML
for taking from a particular cell 从这样的表中,您可以接受使用document.getElementById("").innerHTML
从特定单元格中获取
<TABLE>
<TR>
<TD id='1'>abc</TD>
<TD id='2'>efg</TD>
<TD id='3'>hij</TD>
</TR>
<TR>
<TD id='4'>lmno</TD>
<TD id='5'>pqr</TD>
<TD id='6'>stu</TD>
</TR>
</TABLE>
you can use document.getElementById("2").innerHTML
for getting efg
您可以使用document.getElementById("2").innerHTML
获取efg
try this it worked for me....... 试试这个对我有用.......
$('#export').click(function() {
//alert('clicked')
var myRows = [];
var $headers = $("th");
var $rows = $("tbody tr").each(function(index) {
$cells = $(this).find("td");
myRows[index] = {};
$cells.each(function(cellIndex) {
myRows[index][$($headers[cellIndex]).html()] = $(this).html();
});
});
var myObj = {};
myObj.myrows = myRows;
//alert(JSON.stringify(myObj));
$.ajax({
type: "POST",
url: "your url",
data: "objdata="+JSON.stringify(myObj),//passing data as json
success: function(result){
//alert('exported');
}
});
});
this will export all data's from table and save as json 这将从表中导出所有数据并另存为json
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.