Html 从javascript函数在div中动态创建按钮

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18104920/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 11:56:16  来源:igfitidea点击:

Create buttons dynamically in a div from a javascript function

javascripthtml

提问by shadsauhduisad

I have a function that returns the data from the sql...

我有一个函数可以从 sql 返回数据...

I need to create buttons in a div called

我需要在名为的 div 中创建按钮

divResult

div结果

here is my function

这是我的功能

function retrieveData(transaction, results) {
   for(var i = 0; i < results.rows.length; i++) {
        var data = results.rows.item(i)['nome'];
        alert(data);
    }
}

回答by Scampbell

There is a very good answer on how to create html elements using javascript here: Creating Dynamic button with click event in javascript.

关于如何使用 javascript 创建 html 元素,这里有一个很好的答案:Creating Dynamic button with click event in javascript

...I would add this as a simple comment but I don't have enough street cred yet.

...我会将此添加为一个简单的评论,但我还没有足够的街头信誉。