我正在尝试获取文本,但是此文本已由made的功能更改。更改后,我无法再获取文本,返回值为NULL。
我尝试使用innerText,innerHTML和textContent,但是都返回null。 我不会发布所有HTML,因为它太大了
//HTML
<h2 id = "p1">PLAYER ONE</h2>//Text that I will change
<img src = "imagens/docinho.png" alt = "1.Docinho" class = "ppg" id = "d1" onclick="avatar(this.id);">
<img src = "imagens/florzinha.png" alt = "2.Florzinha" class = "ppg" id = "f1" onclick="avatar(this.id);">
<img src = "imagens/lindinha.png" alt = "3.Lindinha" class = "ppg" id = "l1" onclick="avatar(this.id);">
当我单击其中之一时,会得到默认文本并更改h2的文本
//JAVASCRIPT
//First change
function avatar(i)
{
var textAlt = document.getElementById(i).alt;
var aux = document.getElementById(i);
var meuId = aux.id;
document.getElementById('p1').innerHTML= textAlt;
}
//When I try get the new text in other function
//It's called by 'onClick'
function joga(celula)
{
if(document.getElementById('p1').innerHTML == "1.Docinho")//Here i try to see whats is inside
{
O.style.backgroundImage = "url('imagens/3.jpg')";
}
}