gpt4 book ai didi

Javascript 将 html 标签的颜色设置回默认颜色而不是假定颜色为黑色

转载 作者:行者123 更新时间:2023-11-29 17:46:51 25 4
gpt4 key购买 nike

I have written the following javascript function to disable a text input field and grey out the associated label when a certain option is selected in a selectbox, conversley when other values are selected the text field is enabled and the label colour is set back变黑。

它有效,但是它假设文本标签一开始是黑色的,但事实可能并非如此,获得原始颜色并将其变回原始颜色的最简单方法是什么,以便在原始颜色时正常工作颜色不是黑色。

或者,标签是否有其他一些属性可用于使其看起来变灰,而不是明确地将颜色设置为灰色。我知道它不能被禁用,但还有其他可以使用的东西吗。

function disableInput(selectbox, inputfield, disableValue) {

select = document.getElementById(selectbox);
selected = select.options[select.selectedIndex].value;
if(selected==disableValue)
{
document.getElementById(inputfield).disabled = true;
document.getElementById(inputfield+"label").style.color='grey';
}
else
{
document.getElementById(inputfield).disabled = false;
document.getElementById(inputfield+"label").style.color='black';
}
}

最佳答案

style.blah 属性设置为空字符串将导致再次应用普通样式表。

或者,您可以在 CSS 中定义样式并从元素中添加和删除类,而不是直接调整其样式。

关于Javascript 将 html 标签的颜色设置回默认颜色而不是假定颜色为黑色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48560278/

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