简体   繁体   English

phonegap动态javascript按钮

[英]phonegap dynamic javascript button

Learning how to use Phonegap to create an Android application I am still experimenting with the fundamentals of HTML and JavaScript. 学习如何使用Phonegap创建Android应用程序我仍在尝试HTML和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: 我有一个databasequery(它可以工作),结果应产生一些文本和一个按钮:

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. 从我所读的内容中,这是使用JavaScript创建按钮的方法。

Full source is available here: http://code.google.com/p/easy-service/source/browse/trunk/EasyService-Common/app/app.html 完整的源代码可以在这里找到: http : //code.google.com/p/easy-service/source/browse/trunk/EasyService-Common/app/app.html

You need to create the button node like this: 您需要像这样创建button节点:

var btn = document.createElement("input");

The parameter you're passing in is the type of element-- in this case, we want an input element. 您传入的参数是元素的类型-在这种情况下,我们需要input元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM