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

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

從動態(tài)表格單元格獲取值并將其值傳遞給 JS 函數(shù)

從動態(tài)表格單元格獲取值并將其值傳遞給 JS 函數(shù)

慕哥9229398 2023-09-21 10:51:48
我使用 JavaScript 動態(tài)創(chuàng)建一個表。我想獲取 的值stationIdCell以便將其傳遞給refreshMETAR()函數(shù)。但是,我不知道如何讓它發(fā)揮作用。任何幫助,將不勝感激。這是我的桌子const metarTableElement = document.querySelector('#metar_table')const rowCount = metarTableElement.rows.lengthif(rowCount > 6){  metarTableElement.deleteRow(rowCount - 1)} else {  const row = metarTableElement.insertRow(1)  var stationIdCell = row.insertCell(0)  stationIdCell.innerHTML = `<button onclick="refreshMETAR(this.innerHTML)">${station_id}</button>`  //I want to pass this value to the function  var latitudeCell = row.insertCell(1)  latitudeCell.innerHTML = `${latitude}`  var longitudeCell = row.insertCell(2)  longitudeCell.innerHTML = `${longitude}`  var rawMETARCell = row.insertCell(3)  rawMETARCell.innerHTML = `${raw_metar}`這是我想要將單元格值傳遞給的函數(shù):const refreshMETAR = () => {  const stationElement    = this.innerHTML //The value of the table cell should be read here  const station           = stationElement.value  const alertPanelElement = document.querySelector('#alert_panel')  console.log(`entered: ${station}`)  validateADDSStation(station)    .then(response => response.json())    .then(json => {      let icao = null      let site = null      try{        icao = json.response.data[0].Station[0].station_id[0]        site = json.response.data[0].Station[0].site[0]      } catch(err) {        alertPanelElement.classList.remove('w3-hide')        alertPanelElement.classList.add('w3-show')        stationElement.focus()        stationElement.select()        console.log("BAD CODE")      }      console.log(`RETURN VALUE FROM VALIDATE: ${icao}`)      if( station !== icao){        console.log(`ICAO ${icao} not found`)        alertPanelElement.classList.remove('w3-hide')        alertPanelElement.classList.add('w3-show')         })      }    })}
查看完整描述

2 回答

?
qq_遁去的一_1

TA貢獻1725條經(jīng)驗 獲得超8個贊

看來您正在嘗試將參數(shù) station_id 作為參數(shù)發(fā)送到函數(shù)刷新METAR 中,以便在單擊按鈕時發(fā)送請求。您的代碼中有兩個問題。

  1. <button onclick="refreshMETAR(this.innerHTML)">${station_id}</button> 我認為上面的語句中的這將引用窗口,而不是按鈕元素或 stationIdCell 元素。

  2. const refreshMETAR = () => { const stationElement = this.innerHTML //The value of the table cell should be read here 您發(fā)送 (this.innerHtml) 作為 params ,但這不是在 param 中使用 a 的方法

請嘗試這個:

stationIdCell.innerHTML = `<button onclick="refreshMETAR('${stationId}')">${station_id}</button>`


const refreshMETAR = (stationId) => {

    const station = stationId

    console.log(`entered: ${station}`)


查看完整回答
反對 回復(fù) 2023-09-21
?
慕尼黑5688855

TA貢獻1848條經(jīng)驗 獲得超2個贊

事件委托典型案例


第一部分:



// GLOBAL

const metarTableElement = document.querySelector('#metar_table')

 

document.addEventListener('click', refreshMETAR )



//...

let rowCount = metarTableElement.rows.length

if (rowCount > 6)

  {

  metarTableElement.deleteRow( --rowCount )

  }

else 

  {

  let row = metarTableElement.insertRow()


  row.insertCell().innerHTML   = `<button class="cl_METAR">${station_id}</button>`

  row.insertCell().textContent = latitude

  row.insertCell().textContent = longitude

  row.insertCell().textContent = raw_metar

//...

點擊按鈕...


function refreshMETAR(evt)

  {

  if (!evt.target.matches('button.cl_METAR')) return  // reject clicks from somewhere else 


  const station =  evt.target.textContent // === value in ${station_id}


  // ...


  }


查看完整回答
反對 回復(fù) 2023-09-21
  • 2 回答
  • 0 關(guān)注
  • 143 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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