[英]How to assign the color to a button based on the value from firebase and change it on press on both firebase and on screen?
[英]Change button value and color both
我也在嘗試更改點擊和顏色的值。 我能夠通過js更改值,但無法更改顏色。 這是我的Js代碼
<script type="text/javascript">
function change(el) {
if (el.value === "P")
el.value = "A";
else
el.value = "P";
}
</script>
這是按鈕:
<td>
<input id="press5" name="press5" type="button" value="<?php echo $ro5[$_SESSION['dyy']] ?>"
onclick="return change(this);" onBlur="checkAvailability5()" class="btn btn-primary"/>
</td>
請幫幫我。 謝謝。
此代碼將更改您的背景顏色,字體顏色和輸入按鈕的值。 這里的工作示例。
<input type="button" value="P" onclick="return change(this);"/>
<script type="text/javascript">
function change( el )
{
if ( el.value === "P" ){
el.value = "B";
el.style.backgroundColor = "lightblue";
el.style.color = "blue";
}else{
el.value = "P";
el.style.backgroundColor = "lightpink";
el.style.color = "red";
}
}
</script>
使用此處閱讀的dom style
對象
function change( el )
{
if ( el.value === "P" ){
el.value = "A";
el.style.backgroundColor = "red";
} else {
el.value = "P";
el.style.backgroundColor = "blue";
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.