簡體   English   中英

如何使用javascript獲取表數據值作為變量

[英]How to get Table data values as variables using javascript

我在瀏覽器上有一個頁面,該頁面以表格格式顯示一些項目。 現在,我想選擇特定的項目(行),然后將那些選定行的數據(列值)作為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();
}

從這樣的表中,您可以接受使用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>

您可以使用document.getElementById("2").innerHTML獲取efg

試試這個對我有用.......

$('#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');
                }  
            });

          });

這將從表中導出所有數據並另存為json

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM