本文介绍了动态将整数值添加到表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我必须添加一个整数值,例如newFeature.OrderTotal中有一个整数值.

If I have to add an integer value, like newFeature.OrderTotal has an integer value in it.

如何在动态创建的表中动态显示它?

How can I show it dynamically in a table that I am creating dynamically?

任何建议将不胜感激.

txt += "<td>"+newFeature.OrderTotal+"</td>"; 

这怎么办?

 function dataSelectHandler(transaction, results){

  // Handle the results
  for (var i=0; i<results.rows.length; i++) {

    var row = results.rows.item(i);

    var newFeature = new Object();

        newFeature.OrderTotal   = row['OrderTotal'];//OrderTotal is coming from `(//"SELECT SUM(amount1) AS OrderTotal FROM budget1 WHERE month='"+hello+"' ";)`
    var q1 = newFeature.OrderTotal;//q1 has an integer value suppose 46
    alert(q1);//here alert box is showing properly value of q1
    }
}

var txt = "";
var myTable = "";
txt += "<table id='myTable' border='5'>";
txt += "<tr>";
txt += "<th>Month</th>";
txt += "<th>Amount</th>";
txt += "</tr>";
txt += "<tr>";
txt += "<td>"+$('#mchoose').val()+"</td>";
txt += "<td>"+q1+"</td>";//m not getting any values in this q1 in the table row
txt += "</tr>";
txt += "</table>";

$('#ss').html(txt);

推荐答案

您需要创建一个包含行和包含元素的数据的表,下面是一个示例:

You need to create a table with rows and data containing your elements, here's an example:

function addTable(parentElementId) {
  var data = [1, 2, 3, 4];
  // Create the table with a row and cell for each data element.
  var t = document.createElement("table");
  t.id = "myTable";
  for (var i=0; i<data.length; i++) {
    var tr = t.appendChild(document.createElement("tr"))
      , td = tr.appendChild(document.createElement("td"));
    td.innerHTML = data[i];
  }
  // Add the table to the given element.
  var p = document.getElementById(parentElementId);
  p.appendChild(t);
}

这篇关于动态将整数值添加到表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 01:49