導航:首頁 > 編程語言 > js怎麼改變按鈕的顏色

js怎麼改變按鈕的顏色

發布時間:2025-02-12 00:26:24

⑴ 需求一個js 或者 jq 通過點擊一個按鈕,來改變2個div的背景顏色

<!DOCTYPEhtml>
<html>
<head>
<metacharset="UTF-8">
<title>jquerycookie</title>
<scriptsrc="http://libs..com/jquery/1.8.0/jquery.min.js"></script>
<title>顏色互換</title>
</head>
<body>
<style>
.div1{width:100px;height:100px;background:#00F;}
.div2{width:100px;height:100px;background:#f00;}
.div3{width:100px;height:100px;background:#3F6;;}
</style>
<divclass="div1"><inputname=""type="checkbox"value="a">AAAAAA</div>
<br>
<divclass="div2"><inputname=""type="checkbox"value="b">BBBBBB</div>
<br>
<divclass="div3"><inputname=""type="checkbox"value="c">cccccc</div>
<br>
<inputname=""type="button"value="點擊">
<script>
$(function(){
$("input:button").click(function(){
varlen=$(":checked").length;
if(len<=1){
alert("請選擇兩種顏色");
}elseif(len>2){
alert("不能超過兩種顏色");
}else{
varbackground1=$(":checked").eq(0).parent().css("background");
varbackground2=$(":checked").eq(1).parent().css("background");
$(":checked").eq(0).parent().css("background",background2);
$(":checked").eq(1).parent().css("background",background1);
}
});
});
</script>
</body>
</html>

⑵ 滑鼠點擊按鈕時變顏色js代碼

<input type="button" id="subBtn" onclick="this.style.backgroundColor='red';showSubscribe()"
class="but1" value="訂閱號管理">
<input type="button" id="msgBtn" onclick="this.style.backgroundColor='red';showMsgCollection()"
class="but1" value="圖文集管理">

⑶ 用js寫 有六個按鈕點擊按鈕會變色 然後其他按鈕恢復原來的顏色

可以使用js的css方法實現點擊按鈕會變色,然後其他按鈕恢復原來的顏色。

具體步驟如下:

需要准備的材料分別是:電腦、瀏覽器、ultraedit。

1、在ue編輯器中新建一個空白的html文件,js文件。

⑷ 如何用js實現點擊按鈕改變表格中的一個單元格的背景顏色

<script language="javascript" type="text/javascript">
function chgbg(id){
var obj=window.document.getElementById(id);
var bg=obj.style.backgroundColor;
if(bg=='') obj.style.backgroundColor='#f00'
else obj.style.backgroundColor=''
}
</script>
<table width="100%" border="1" cellspacing="0" cellpadding="4">
<tr>
<td id="td1"> </td>
<td id="td2"> </td>
<td id="td3"> </td>
</tr>
<tr>
<td id="td4"> </td>
<td id="td5"> </td>
<td id="td6"> </td>
</tr>
</table>
<input type="button" value="點擊改變指定單元格回背景答" onClick="chgbg('td1');" />

⑸ JS設置點擊按鈕改變DIV的顏色,兩種顏色切換改變。

1、background=='#000'
2、oDiv.style.dbackground='FF0000';dbackground 拼錯了

⑹ 求助~怎麼實現按鈕點擊一次之後,按鈕不能再點擊了,變為灰色,下面代碼怎麼更改

1、首先新建html頁面,抄設置一個button按鈕。

⑺ js循環5個按鈕,實現點擊每個按鈕彈出對應的顏色(紅黃粉 綠藍)

<html>
<script type="text/javascript">
function f(n)
{
switch(n)
{
case 0:
alert("紅");
break;
case 1:
alert("黃");
break;
case 2:
alert("粉");
break;
case 3:
alert("綠");
break;
case 4:
alert("藍");
break;
}
}
</script>
<form>
<input type="button" value="紅" onclick="f(0)" />
<input type="button" value="黃" onclick="f(1)" />
<input type="button" value="粉" onclick="f(2)" />
<input type="button" value="綠" onclick="f(3)" />
<input type="button" value="藍" onclick="f(4)" />
</form>
</html>

閱讀全文

與js怎麼改變按鈕的顏色相關的資料

熱點內容
現場管理有哪些文件 瀏覽:713
linuxapache集群 瀏覽:406
代碼修改form名稱 瀏覽:507
華為g9是安卓系統嗎 瀏覽:688
貝葉斯網路構建方法 瀏覽:197
模仿網站素材哪裡來 瀏覽:488
小程序選擇器時間 瀏覽:47
win10任務管理器頻率 瀏覽:583
禹城市網路傳媒怎麼樣 瀏覽:629
招商applepay免密 瀏覽:828
超市收銀數據怎麼核對 瀏覽:716
win10電腦壁紙問題 瀏覽:778
右鍵單擊桌面文件無反應 瀏覽:941
ftp文件名帶時間 瀏覽:547
java面試題抽象類和介面有什麼區別 瀏覽:984
mac電腦壓縮文件到windows 瀏覽:258
如何刪除qq最近聯系人 瀏覽:228
iphone6關閉單手 瀏覽:831
3扣1用什麼app 瀏覽:387
簡單內核程序 瀏覽:675

友情鏈接