问题描述:

How to create Table plugin dynamically using javascript api's in jquery mobile.

Now i'm creating table plugin using append method in javascript, but i want create this in javascript api's.

Html

 <table data-role="table" data-mode="columntoggle" class="ui-responsive table ui-shadow" id="today_app">

<tr><th>Name</th><th>Duration</th></tr>

</table>

javascript

for (var i = 0; i < serviceName.length; i++) {

$('#today_app').append('<tr><td>'+serviceName[i].name+'</td><td>'+serviceName[i].from+'</td></tr>');

}

网友答案:

Code without jquery mobile append...

var   = document.getElementById('today_app');
for (var i = 0; i < serviceName.length; i++) {
    var row       = document.createElement("tr");  
    // create table cells
    var td1       = document.createElement("td");
    var td2       = document.createElement("td");
    td1.innerHTML = serviceName[i].name;
    td2.innerHTML = serviceName[i].form;
    // adding cells to row
    row.appendChild(td1);
    row.appendChild(td2);
    tableObj.appendChild(row);
}
相关阅读:
Top