想要自动打印页面加载数据

时间:2016-08-04 11:22:34

标签: jquery

这是在点击按钮"显示"我希望它得到负载,因为页面加载简短我不想点击打印用户名它应该自动打印

$(document).ready(function(){
var myDB;
//Open Database Connection
document.addEventListener("deviceready",onDeviceReady,false);
function onDeviceReady()
{
    myDB = window.sqlitePlugin.openDatabase({name: "mydb.db", location: 'default'});
}


    $("#show").click(function()
    {
        $("#user_name").html("");
        myDB.transaction(function(transaction) 
        {
            transaction.executeSql('SELECT * FROM phonegap', [], function (tx, results)
            {
                var len = results.rows.length, i;
                for (i = 0; i < len; i++)
                {
                    $("#user_name").append("<p>"+results.rows.item(i).title+"</p>");
                }
            }, null);
        });
    });});



<h1 id="user_name" class="call-btn" style="color:white"><p></p></h1><button id="show">show</button>

1 个答案:

答案 0 :(得分:0)

<强> JS

$(document).ready(function(){
  var myDB;

  //Open Database Connection
  document.addEventListener("deviceready",onDeviceReady,false);

  function updateUsername(){
    $("#user_name").empty();
    myDB.transaction(function(transaction){
      transaction.executeSql('SELECT * FROM phonegap', [], function (tx, results){
        var len = results.rows.length, i;
        for (i = 0; i < len; i++){
          $("#user_name").append("<p>"+results.rows.item(i).title+"</p>");
        }
      }, null);
    })
  }

  function onDeviceReady(){
    myDB = window.sqlitePlugin.openDatabase({name: "mydb.db", location: 'default'});
    updateUsername();
  }
});

<强> HTML

<h1 id="user_name" class="call-btn" style="color:white"></h1>