導航:首頁 > 編程語言 > 點擊按鈕變背景顏色js

點擊按鈕變背景顏色js

發布時間:2021-10-07 14:09:24

javascript點擊按鈕改變背景色的問題

js直接修改style的背景色就可以了,
下面是代碼,僅供參考:
<script>
window.onload = function(){
var oBtn = document.getElementById('btn');
oBtn.onclick = function(){
this.style.backgroundColor = 'red';s
};
};
</script>
</head>
<body>
<input type="button" id="btn" value="click me" />
</body>

❷ js 通過button按鈕onclick事件改變背景顏色 如何切換性改變

<HTML>
<head>
<script>
function mychange()
{
var color = document.getElememtById("colorType").value;
if(color == "red")
{

document.getElementById("div1").style.background="blue";
document.getElememtById("colorType").value = "blue";
}
else if(color == "blue")
{
document.getElementById("div1").style.background="red";
document.getElememtById("colorType").value = "red";
}

}
</script>
</head>
<body>
<table id="div1" style="height:80px; width:800px; background:red">
<input type="hidden" value="red" id="colorType" />
<input type="button" value="第一個按鈕" onclick="mychange()" />
</table>

</body>
</HTML>

這是一種簡單的方式實現。還有很多中解決方案,你可以再拓展一下。

❸ 如何用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怎麼設置點擊按鈕切換背景

var size = 5,current = 0,gx = document.getElementById("gx");

function next(){

current = (current+1)%size;

change();

}

function prev(){

current = (current+size-1)%size;

change();

}

function change(){

gx.style.backgroundImage="url(images/gx"+(current+1)+".jpg)";

}

setInterval(next,1000);

按鈕
<inputtype="button"onclick="prev()"value="prev"/>
<inputtype="button"onclick="next()"value="next"/>

❺ 滑鼠點擊按鈕時變顏色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="圖文集管理">

❻ 如何用javascript改變按鈕背景色樣式

這個有一個簡單的方抄法
比如,你有兩個按鈕的樣式,一個是class_1,一個是class_2,
你只需要給一個觸發,
<button id="my_button" class="class_1"></button>
<input type="button" onclick="change();" value="改變顏色"/>
<script>
function change(){
var class=document.getElementById('my_button').value;
if(class=='class_1'){
document.getElementById('my_button').class='class_2';
}
else{
document.getElementById('my_button').class='class_1';
}
</script>

❼ 需求一個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點擊切換背景顏色

<script>
window.onload=document.onclick=()=>{
let c=()=>parseInt(Math.random()*256);
document.body.style.backgroundColor="rgb("+c()+","+c()+","+c()+")";
}
</script>

❾ js把正在點擊的輸入欄變換背景顏色

頁面加完成執行一下方法監聽input框的onfocus事件

在這個輸入框獲得交點時觸發一下事件將紅色去掉方法如下

window.onload=function(){
listenInputFocus();
}
listenInputFocus=function(){
varinputs=document.getElementsByTagName("input");
for(vari=0;i<inputs.length;i++){
inputs[i].onfocus=function(){
this.style.backgroundColor='';
}
}
}

❿ javascript 點擊一行中的一個按鈕,使該行的背景顏色變為紅色

<volistname="list"id="vo">
<tr>
<td>asd</td>
<td>asd</td>
<td>asd</td>
<td><aclass="isAdvbtn"onclick="showred(this);">按鈕</a></td>
</tr>
</volist>
<scripttype="text/javascript>
functionshowred(obj){
obj.parentElement.parentElement.style.backgroundColor="#FF0000";
}
</script>

閱讀全文

與點擊按鈕變背景顏色js相關的資料

熱點內容
注冊表修復工具win7 瀏覽:186
javapdfdpi 瀏覽:267
魔獸50後在哪升級 瀏覽:78
linux怎麼查看當前目錄的大小 瀏覽:607
ipad連接iphone上網 瀏覽:758
怎麼看微信定位真假 瀏覽:678
u盤文件被360隱藏 瀏覽:791
夢幻西遊寵物升級時間 瀏覽:107
做一個貨源網站要多少錢 瀏覽:828
怎麼用手機自己創造一個app 瀏覽:396
php下載文件實現 瀏覽:720
iphone4換機政策 瀏覽:804
在哪裡找py文件的下載路徑 瀏覽:224
蘋果7電話怎麼設置密碼 瀏覽:56
百聯實體卡怎麼綁定app 瀏覽:512
oa系統的文件支持哪些格式 瀏覽:791
網站git是什麼 瀏覽:867
為什麼投入編程行業 瀏覽:870
pdm文件怎麼打開mac 瀏覽:800
如何電腦連接網路 瀏覽:556

友情鏈接