簡體   English   中英

從單元格中獲取文本框值

[英]Get a text box value from a cell

我用PHP創建了一個表。

 echo "<td class=\"normalfnt\"  width=\"10\"  style=\"text-align:left; padding-left:9px;\" id=\"weightType\"/>$Description</td>";
             echo "<td class=\"normalfnt\" width=\"30\" > <input type=\"text\" size=\"6px\" id=\"fuelCost\" name=\"fc\"/></td>";

現在我想得到燃料成本的文本框值。 因為我試圖使用以下貝婁javascript函數

 function GetCellValues() {
  // alert('hi');
    var table = document.getElementById('tbl');

    //row.cells[index].getElementsByName('inputcell' + index)[0].value

    for (var r = 1, n = table.rows.length; r < n; r++) {
        for (var c = 0, m = table.rows[r].cells.length; c < m; c++) {
           alert(table.rows[r].cells[c].innerHTML);
        }
    }
}

現在我面臨的問題是它不會給我正確的輸出。 但是html文本框代碼我已經放入了PHP代碼表..如果有人可以幫我這個,我會非常感激。

由於您已使用jQuery標記,請嘗試此解決方案

function GetCellValues() {
    //find all input elements with name fc within element with id table
    $('#tbl input[name="fc"]').each(function(){
        console.log($(this).val())
    });
}

嘗試這個

var values = $('#tbl').find('td > input[type="text"]').map(function(v){
    return v.value;
}).get();

這個怎么樣,

function check()
{
    var table = document.getElementById("tbl");
    for (var i = 0, row; row = table.rows[i]; i++) {
       for (var j = 0, col; col = row.cells[j]; j++) {
            if(col.firstChild.nodeName=="INPUT")
            {
                console.log(col.firstChild.value);
            }
       }  
    }
}

暫無
暫無

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

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