⑴ 需求一個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>