第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

將變量分配給單個(gè)表格單元格

將變量分配給單個(gè)表格單元格

九州編程 2021-06-29 09:51:52
我正在嘗試將圖像放入表格中。我有這個(gè)工作,如果你點(diǎn)擊,你會在可用的選項(xiàng)中循環(huán)。但是,計(jì)數(shù)器與單元格無關(guān),它是一個(gè)全局計(jì)數(shù)器。有沒有辦法創(chuàng)建一個(gè)局部變量來跟蹤單個(gè)單元格在數(shù)組中的位置?我曾嘗試為一個(gè)單元格創(chuàng)建一個(gè)局部變量,但它不起作用。下面是js中的相關(guān)函數(shù):var i = 1;var table = document.getElementsByTagName('table')[0];var def = ["tex/white.png", "tex/grass.jpg", "tex/stone.jpg", "tex/water.jpg", "tex/wood.jpg", "tex/lava.jpg"];table.onclick = function(e) {    var target = (e || window.event).target;    if (target.tagName in { TD: 1, TH: 1 }) {        target.className = "img";        console.log((e || window.event).target);        target.setAttribute('style', 'background-image:' + "url(" + def[i] + ")");        if (i < def.length) {            i++        }        if (i == def.length) {            i = 0;        }    }};這是我到目前為止所做的工作的小提琴:https ://jsfiddle.net/6L0armd4/期望的結(jié)果是我從單個(gè)單元格開始陣列,它只對這些單元格計(jì)數(shù)。目前,它總是提供下一個(gè)紋理,即使我選擇了不同的單元格。
查看完整描述

2 回答

?
慕的地6264312

TA貢獻(xiàn)1817條經(jīng)驗(yàn) 獲得超6個(gè)贊

您需要制作偵聽器事件,您可以在下面的代碼中將顏色代碼更改為您的圖像路徑,并避免任何本地路徑圖像鏈接問題嘗試使用在線圖像直接鏈接。


var table = document.querySelector('#table')

var selectedCells = table.getElementsByClassName('selected')


table.addEventListener('click', function(e) {

var td = e.target


if (td.tagName !== 'TD') {

return

}


if (selectedCells.length) {

selectedCells[0].className = ''    

}


td.className = 'selected'

})

table {

 cursor: text;

}

tr {

background-color:white;

}

td {

font-size: 14;

cursor: default;

}


td.selected {

background-color: red;


 // replace this with background image tag like this  

 background-image: url("paper.gif



<table border="1" cellpadding="8" cellspacing="2" id="table">

<tr>

<td>Cell one</td>

<td>Cell Tw</td>

<td>Cell three</td>

<td>Cell Four</td>

<td>Cell five</td>

<td>Cell sex</td>

<td>Cell five</td>

<td>cell seven</td>

<td>cell eight</td>

<td>cell nine</td>

<td>cell tens</td>

<td>cell eleven</td>

<td>cell twelve</td>

</tr>

<tr>

<td>AKo</td>

<td>KK</td>

<td>KQs</td>

<td>KJs</td>

<td>KTs</td>

<td>K9s</td>

<td>K8S</td>

<td>K7s</td>

<td>K6s</td>

<td>K5s</td>

<td>K4s</td>

<td>K3s</td>

<td>K2s</td>


查看完整回答
反對 回復(fù) 2021-07-08
  • 2 回答
  • 0 關(guān)注
  • 195 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號