onclick не обновляется. Показывает старое значение даже после использования .onclick = "hideList ()"; - PullRequest
0 голосов
/ 26 января 2019

Значение onclick не заменяется.Окно консоли показывает его как неизменное.Вот код JavaScript:

function viewList(){
  var c=document.querySelector(".list");
  c.style.display= "block";
  document.querySelector(".box").style.height="700px";
  document.getElementById("btn").onclick="hideList()";
  console.log(document.getElementById("btn"));
}
function val(p){
  var i=document.getElementsByClassName("valued");
  var j=document.createAttribute("value");
  j.value=p.textContent;
  i[0].setAttributeNode(j);
}       
function hideList(){
  var c=document.querySelector(".list");
  c.style.display= "none";
  document.querySelector(".box").style.height="500px";
}

1 Ответ

0 голосов
/ 26 января 2019
//if you want to set string at function use this way
document.getElementById("btn").setAttribute('onclick',"hideList()");
//if you want set function variable then 
document.getElementById("btn").onclick=hideList;

Обновление:

//This will set the method to a string
document.getElementById("btn").onclick="hideList()";
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...