導航:首頁 > 編程語言 > js單元格點擊過變色

js單元格點擊過變色

發布時間:2021-10-10 23:13:48

⑴ 求一個javascript功能,實現點擊過的菜單變色。

建議用jquery庫實現.
具體是4個菜單的母容器設ID=mother,4個菜單分別在一個li里如下
<ul id="mother">
<li onclick="changeClass(this)";></li>
</ul>
function changeClass(a)
{
$("#mother").children("li").removeClass("被點擊的菜單的CSS類");
$(a).addClass("被點擊的菜單的CSS類");
}

如果不用jquery會比較麻煩但是也可以寫
function changeClass(a)
{
document.getElementById("mother").getElementsByTagName("li").className="未被點擊的CSS類";
a.className="被點擊菜單的CSS類";
}
我也忘了是不是className了,你跟蹤一下看看有問題也是大小寫的問題.但jquery的方法應該是沒錯的.

像你圖片里的菜單html應該差不多這么寫
<div id="mother">
<div class="menu">
<span>硬體產品<span>
<ul>
<li onclick="changeClass(this)";>終端產品</li>
<li onclick="changeClass(this)";>軟體產品</li>
</ul>
</div>
</div>
css這方面的問題在寫就多了,你估計看著也煩。具體就是也寫background,text-alain 和float的問題。應該不難寫。
ps:你這不叫單擊過的菜單變色.二是當前選中的菜單變色.謝謝

js實現點擊一個按鈕,表格中某行變色,按鈕的value與表格中列name值相同的行變色

<table>
<tr id="r1">
<td name="r1c1"><input id="button" type="button" value="r1" onClick="changeColor(this)"/></td>
</tr>
<tr id="r2">
<td name="r2c1"><input id="button" type="button" value="r2" onClick="changeColor(this)"/></td>
</tr>
</table>

<script>
function changeColor(obj){
var tri = obj.value;

document.getElementById(tri).style.backgroundColor = 'red';
}

</script>
不通的話自己調一下,盲寫的。

⑶ JS 點擊改變顏色

document.getElementById(id).style.color = '顏色值';
你的只是點到style這里,你要再點到color這里才行。

⑷ js滑鼠點擊變顏色

<!DOCTYPEhtml>
<htmllang="en">
<head>
<metacharset="UTF-8">
<title>Document</title>
</head>
<body>
<divonclick="cbg()"style="width:200px;height:200px;border:1pxsolidred;">
<ahref=""id="tr">a</a>
<ahref="">b</a>
</div>
</body>
<script>
functioncbg(){
document.getElementById('tr').style.backgroundColor="#222";
}
</script>
</html>

⑸ JS點擊變色的問題

$(document).ready(function onClickColor(td) {
if (td.style.backgroundColor != '')
{
td.style.backgroundColor = '';
td.style.color = '';
}
else
{
td.style.backgroundColor = '#FFFF99';
td.style.color = '#0600FF';
}
});

<table class="sortable" onclick="onClickColor(this);" style="cursor:move">

⑹ js實現變色,表格中的數據在查看時,顯示為紅色,當點擊過該條數據後,數據的顏色由紅色變黑色

為什麼要用js呢,這個完全可以用a 標簽的css屬性來完成的呀。
以下為css代碼
a{ } 默認的值
a:link {} /* 未訪問的鏈接 */
a:visited {} /* 已訪問的鏈接 */
a:hover {} /* 當有滑鼠懸停在鏈接上 */
a:active {} /* 被選擇的鏈接 */

⑺ js點擊變色

直接在google瀏覽器的審查元素的console試試。

⑻ 求用JS或jquery實現點擊表格同步變色

<!DOCTYPEhtml>
<html>
<head>
<metacharset="UTF-8">
<title>Document</title>
<style>
.tab1,
.tab2{
border-collapse:collapse;
border:none;
width:200px;
}
.tab1td,
.tab2td{
border:1pxsolid#000;
text-align:center;
}
.tab1td{
cursor:pointer;
}
.tab2{
margin-left:40px;
}

.bg1{
background:red;
}
.bg2{
background:green;
}
.bg3{
background:orange;
}
</style>
</head>
<body>
<menu>
<table>
<tr>
<td>01</td>
<td>11</td>
<td>12</td>
<td>22</td>
<td>23</td>
<td>33</td>
</tr>
</table>
</menu>
<hr>
<table>
<tr>
<td>01</td>
<td>02</td>
<td>03</td>
<td>04</td>
<td>05</td>
<td>11</td>
</tr>
<tr>
<td>12</td>
<td>13</td>
<td>14</td>
<td>15</td>
<td>16</td>
<td>22</td>
</tr>
<tr>
<td>23</td>
<td>24</td>
<td>25</td>
<td>26</td>
<td>27</td>
<td>33</td>
</tr>
<tr>
<td>01</td>
<td>11</td>
<td>12</td>
<td>22</td>
<td>23</td>
<td>33</td>
</tr>
</table>

<script>
;(function(){
varaBtn=document.querySelectorAll('.tab1td');
varaConTd=document.querySelectorAll('.tab2td');

~function(){
for(vari=0;i<aConTd.length;i++){
aConTd[i].dataset.cls=aConTd[i].className;
}
}();
functionremoveConTdBg(text){
for(vari=0;i<aConTd.length;i++){
if(aConTd[i].innerText===text){
aConTd[i].classList.remove(aConTd[i].dataset.cls);
}
}
}
functionaddConTdBg(text){
for(vari=0;i<aConTd.length;i++){
if(aConTd[i].innerText===text){
aConTd[i].classList.add(aConTd[i].dataset.cls);
}
}
}

for(vari=0;i<aBtn.length;i++){
aBtn[i].bSign=true;
aBtn[i].strClass=aBtn[i].className;
aBtn[i].onclick=function(){
if(this.bSign){
//去掉class,和判斷相應的td
this.classList.remove(this.strClass);
removeConTdBg(this.innerText);
}else{
//加上class
this.classList.add(this.strClass);
addConTdBg(this.innerText);
}
this.bSign=!this.bSign;
};
aBtn[i].onmousedown=function(){
returnfalse;
};
}
})()
</script>
</body>
</html>

注意:裡面用到了很多h5的新語法,所以低版本的瀏覽器不兼容,請自行更改。

⑼ 如何用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');" />

⑽ Javascript如何實現點擊過的文字背景變色

<aid="word"href="#">點擊變色來</a>

var a = document.getElementById("word");

a.onClick = function (){

this.style.color = /*希望源字體改變的顏色值*/;

return false; //阻止頁面跳轉;

}

閱讀全文

與js單元格點擊過變色相關的資料

熱點內容
vivox6和蘋果6 瀏覽:611
編程苦惱怎麼辦 瀏覽:140
vuejsref動態改變 瀏覽:171
哪些軟體可用於文件解壓 瀏覽:701
農行u盾原始密碼 瀏覽:371
xp如何弄出一個無線網路連接 瀏覽:569
word插入pdf只顯示文件名稱和圖標 瀏覽:150
我想編程一個小軟體怎麼弄 瀏覽:168
如何優化文件讀取數據java 瀏覽:262
java敏捷式開發 瀏覽:800
網頁對齊代碼快捷鍵是什麼 瀏覽:304
tomcatlinux文件目錄 瀏覽:520
三星手機能升級系統嗎 瀏覽:683
linux創建文件夾在哪 瀏覽:623
javadatetimezone 瀏覽:434
cf那些文件沒有用 瀏覽:502
蘋果官方網站的手機質量怎麼樣 瀏覽:801
微信存儲數據的文件叫什麼 瀏覽:94
js腳本不起作用 瀏覽:317
iphone3g怎麼升級 瀏覽:341

友情鏈接