HTML5表行动态添加数据

时间:2015-03-14 12:50:54

标签: html5 cordova html-table tablerow

我在phonegap中创建一个应用程序,我在其中显示数据库w中某个人的出生日期详细信息。并且详细信息存储在localstorage中..但是当我试图在表格中显示细节时它不起作用..如果有任何身体可以帮助..请帮助..我在下面给我的代码..

</head> 
<body onload="onLoad();">    
<div class="app">
<label id="naming">Saved Data</label>
<br>
<br>
<table id="myTable" border="1" style="width:100%">
<thead>
<tr>
<th>Full details</th>
</tr>
</thead>
<tr id="first">
    <td>First Name</td>   
     <td id="tbfn">First Name</td>   
  </tr>
<tr id="middle">
    <td>Middle Name</td>
    <td ></td>         
  </tr>
<tr id="last">
    <td>Last Name</td> 
    <td ></td>        
  </tr>
<tr id="day">
    <td>Day of birth</td>
    <td></td>         
  </tr>
<tr id="month">
    <td>Month of Birth</td> 
    <td></td>        
  </tr>
<tr id="year">
    <td>Year of Birth</td> 
    <td></td>        
  </tr>
</table>
</div>

<script type="text/javascript" src="cordova.js"></script>        
<script type="text/javascript" src="js/index.js"></script>

<script type="text/javascript">
  app.initialize();
function onLoad() {
    var table = document.getElementById("myTable");   
   document.getElementById("tbfn").innerHTML = localStorage.getItem('fnm');
}
</script>  
</body>
</html>

1 个答案:

答案 0 :(得分:2)

当您使用简单字符串替换localStorage.getItem('fnm')时,这非常有效

document.getElementById("tbfn").innerHTML = 'John';

JSFiddle

所以,问题是localStorage没有被填入其他页面。这意味着,您必须检查fnm的值,例如

var fnm = localStorage.getItem('fnm');
console.log('fnm=' + fnm);

并在另一页中查找错误,其中应设置值。