JavaScript 查询选择器失败
JavaScript QuerySelector failed
有人知道为什么 querySelector 不起作用吗?
var itemID ="8zoncALaudovCbLRYGbx";
console.log(document.getElementById(itemID)); //work
console.log(document.querySelector("."+itemID)); //not work why ? (error :"not a valid selector")
console.log(document.querySelector("#"+itemID)); // not work why ? (error :"not a valid selector")
<div class="8zoncALaudovCbLRYGbx" id="8zoncALaudovCbLRYGbx">useless text</div>
使用这个功能
function EditModal(itemID) {
const mod = document.querySelector(".edit-modal");
document.body.style = "overflow:hidden; position :absolute;height:100%";
const test = document.getElementById(itemID);
console.log(document.querySelector('div[id="'+`${itemID}`+'"]'));
mod.innerHTML = `"$⏪for testing"{document.querySelector("div."+itemID+",.title")}`;
}
有人知道为什么 querySelector 不起作用吗?
var itemID ="8zoncALaudovCbLRYGbx";
console.log(document.getElementById(itemID)); //work
console.log(document.querySelector("."+itemID)); //not work why ? (error :"not a valid selector")
console.log(document.querySelector("#"+itemID)); // not work why ? (error :"not a valid selector")
<div class="8zoncALaudovCbLRYGbx" id="8zoncALaudovCbLRYGbx">useless text</div>
使用这个功能
function EditModal(itemID) {
const mod = document.querySelector(".edit-modal");
document.body.style = "overflow:hidden; position :absolute;height:100%";
const test = document.getElementById(itemID);
console.log(document.querySelector('div[id="'+`${itemID}`+'"]'));
mod.innerHTML = `"$⏪for testing"{document.querySelector("div."+itemID+",.title")}`;
}