有没有方法通过编程方式更改按钮的颜色或至少是按钮标签的颜色? 我可以改变以编程方式更改按钮颜色
document.getElementById("button").object.textElement.innerText = "newlabel";
但如何改变颜色标签本身?
有没有方法通过编程方式更改按钮的颜色或至少是按钮标签的颜色? 我可以改变以编程方式更改按钮颜色
document.getElementById("button").object.textElement.innerText = "newlabel";
但如何改变颜色标签本身?
下面是一个使用HTML的例子:
<input type="button" value="click me" onclick="this.style.color='#000000';
this.style.backgroundColor = '#ffffff'" />
这里是使用JavaScript的例子:
document.getElementById("button").bgcolor="#Insert Color Here";
对不起,我把我的回复放在上面两篇文章的所有文章中,是到了晚些时候:-( 所以只是重复一次,没有任何提案可行,尽管最后一篇我不明白,所以我没有尝试。 感谢进一步提示 – Zsolt 2009-12-01 06:53:19
我相信你想要的bgcolor。事情是这样的:
document.getElementById("button").bgcolor="#ffffff";
这里有几个演示,可以帮助:
可能是最好的改变的className:
document.getElementById("button").className = 'button_color';
然后你可以在你可以加CSS的地方添加一个buton风格n设置背景颜色和其他任何东西。
我终于找到一个工作代码 - 试试这个:
document.getElementById("button").style.background='#000000';
document.getElementById(“submit_button”)。style.backgroundColor ='lightgreen'; //这将保持悬停颜色变化 – xinthose 2015-04-15 16:02:14
use jquery : $("#id").css("background","red");
+1只是因为我认为没有理由的人投票下来。 – Jimmeh 2009-11-30 13:43:19