gpt4 book ai didi

javascript - 如何将样式添加到单击另一个按钮时创建的按钮?

转载 作者:搜寻专家 更新时间:2023-10-31 08:44:04 26 4
gpt4 key购买 nike

我有这个按钮,只要你点击另一个按钮就会加载(所以它不会在启动时加载而我没有做任何事情)

<button type='button' id='testbtn' 
onclick='testfunction()' onload='testload()'
class='testbtnclass'>btn</button>

这是我的功能:

 function testload() {

alert("onload worked");
/*what i want to archieve within this function later is to change the
css of the button but for now i just want to call this function onload of
the button, which it doesnt/*
}

我现在的问题是,我应该怎么做才能在加载此按钮时运行此功能?

最佳答案

onload 不受 button 标签支持,因此您需要像其他答案一样或使用

来完成
document.onload =function(){

//change the css of that button or call function you want

}

关于javascript - 如何将样式添加到单击另一个按钮时创建的按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29962851/

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