자바 스크립트 변수에 문제가 있습니다. 내 상황은 : PHP 파일에서JavaScript를 사용하여 변수 충돌
내가 가진 : JS 파일에서
<div class="fd_text" onmouseover="zobraz_text('pom','1','1')" onmouseout="zobraz_text('pom','1','0')">something in</div>
나는이 :
var pom1 = "Some text1";
var pom2 = "Some text2";
function zobraz_text(firma, cislo, udalost){
obsah_text = firma+cislo; //this is wrong and why I wrote lower in text under this code
document.getElementById("bloks").innerHTML = document.getElementById("bloks").innerHTML + obsah_text; //this ID is correct
}
obsah_text
하는 등 pom1
, pom2
에서 텍스트를 추가해야하는 변수입니다 ...
여기서 pom1
및 pom2
은 PHP 파일에있는 mouseover
에서 가져옵니다.
zobraz_text
에서 I 그룹 처음 두 parametrs 나는
pom1
을 준 경우, 그러나이
pom1
내가 텍스트가
pom1
과 동일한 밤은. 웹상에는
"pom1"
텍스트가 있지만 텍스트는
"Some text1"
이어야합니다.
내 코드는 변수 obsah_text
을 삭제하고이 예제 코드 에서처럼 변수 pom1
을 추가하기 만하면 작동합니다.
이 변수에서 나에게 텍스트를 표시하고이 괜찮습니다하지만 변수를 추가하는 경우 다음이 코드는 300 상황 1에서 작동
document.getElementById("bloks").innerHTML = document.getElementById("bloks").innerHTML + pom1;
I (그것을 위해 내가 처음이와 기능 zobraz_text()
에서 두 번째 parametrs) 네가 나를 이해하고 도와 준다고 믿는다. 나는 그것이 당신들 중 많은 사람들에게 단순 할 것이라고 기대합니다.
그것은 작동합니다, 감사합니다. +1 –