Learning how to use Phonegap to create an Android application I am still experimenting with the fundamentals of HTML and JavaScript. Trying to add a button, I must have done something fundamentally wrong...
this is my body element:
<div data-role="page">
<div data-role="header">
<h1>My Title</h1>
</div>
<div data-role="content" id="divContent">
<p id="content"></p>
</div>
</div>
To start with I have some basic functionaloty. I have a databasequery (it works) and the result should produce some text and a button:
if(results.rows.item(0).c == 0){
document.getElementById("content").innerHTML=
"You don't have any service items ....etc";
var btn = document.createElement("newItem");
btn.setAttribute("type", "button");
btn.setAttribute("value", "AAARGH!");
btn.setAttribute("name", "btnNew");
document.getElementById("divContent").appendChild(btn);
}
The text is displayed, the button is not and I cannot understand why. From what I have read this is the way to create a button with JavaScript.
Full source is available here: http://code.google.com/p/easy-service/source/browse/trunk/EasyService-Common/app/app.html
You need to create the button
node like this:
var btn = document.createElement("input");
The parameter you're passing in is the type of element-- in this case, we want an input
element.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.