0

任何人都知道为什么 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>

4

1 回答 1

0

使用这个功能

   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")}`;
}
于 2020-04-13T23:51:28.357 回答