我使用 JavaScript 动态创建一个表。我想获取 的值stationIdCell以便将其传递给refreshMETAR()函数。但是,我不知道如何让它发挥作用。任何帮助,将不胜感激。
这是我的桌子
const metarTableElement = document.querySelector('#metar_table')
const rowCount = metarTableElement.rows.length
if(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}`
这是我想要将单元格值传递给的函数:
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')
})
}
})
}
qq_遁去的一_1
慕尼黑5688855
相关分类