gpt4 book ai didi

javascript - 计数器按钮和新按钮

转载 作者:太空狗 更新时间:2023-10-29 16:45:43 25 4
gpt4 key购买 nike

我正在尝试创建一个按钮,当点击它时它会返回它被点击的次数以及你每次点击该按钮的次数;

A new button is added to the page(It's a new button so it hasn't been clicked yet) 添加到页面的每个按钮都应该具有与第一个按钮相同的交互。单击它会增加它的值并在页面上创建新按钮。

到目前为止,我已经弄清楚了计数器按钮,但似乎无法在页面上添加该按钮。请帮助...

var clicks = 0;
function onClick(){
clicks +=1;
document.getElementById("button").innerHTML= "I've been clicked " +clicks +
" times" ;
};

最佳答案

createElement() 方法可能是最简单的方法... http://www.w3schools.com/jsref/met_document_createelement.asp

var clicks = 0;
var button = 0;
function onClick(){
clicks +=1;
button++
document.getElementById("button").innerHTML= "I've been clicked " +clicks +
" times" ;
var newButton = document.createElement("button"+button);
document.body.appendChild(newButton);
document.getElementById("button"+button).innerHTML = "I Have Not Been Clicked Yet"
};

关于javascript - 计数器按钮和新按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31644338/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com