2012-01-02 3 views
2

안녕하세요 여러분, 제가 가지고있는 자바 스크립트 코드 내에 html을 올바르게 표시하는 데 문제가 있습니다. 기본적으로 변수 hundo가 3과 같은지 확인한 다음 스크립트에서 양식을 표시하도록합니다. hundo가 3 일 때 경고 메시지 만 표시하도록 코드를 테스트했지만 document.write를 사용하면 작동하지 않습니다. ,자바 스크립트에서 html을 사용하는 데 문제가 있습니까?

document.write('<form action="insert.php" method="post"> 
Link URL: <input type="text" name="linkurl" /> 
<input type="submit" /> 
</form>'); 

문제는 당신이 단지 따옴표의 한 종류를 사용하고 있습니다 : 내 생각 엔 ... 문제가있다 당신은 당신의 document.write에 사용하는 따옴표를 대체 할 필요가

<script> 
setInterval(function(){ 
if(hundo == '3'){ 
document.open(); 
document.write("<form action="insert.php" method="post"> 
Link URL: <input type="text" name="linkurl" /> 
<input type="submit" /> 
</form>"); 
document.close(); 
} 
}, 1000); 
</script> 

답변

1

입니다 그래서 자바 스크립트는 정의되지 않은 자바 스크립트 객체 인 insert.php보다 "<form action="을보고, 아무런 연산자도없이 부팅합니다.

+0

당신이 말을하는 것은 완전한 감각을 만든다 그래도 아직 작동하지 않습니다. – Twister

+0

"여전히 작동하지 않습니다."- 정확히 무엇을 의미합니까? 오류 콘솔은 무엇을 말합니까? – Oded

+0

오류 콘솔은 hundo = 3 일 때 양식이 나타나지 않는다고 말하지 않습니다. – Twister

1

문제는 document.write를에서 문자열이

<script> 
setInterval(function(){ 
if(hundo == '3'){ 
document.open(); 
document.write('<form action="insert.php" method="post"> 
    Link URL: <input type="text" name="linkurl" /> 
    <input type="submit" /> 
</form>'); 
document.close(); 
} 
}, 1000); 
</script> 
1
<script> 
setInterval(function(){ 
if(hundo == '3'){ 
document.open(); 
document.write('<form action="insert.php" method="post"> 
Link URL: <input type="text" name="linkurl" /> 
<input type="submit" /> 
</form>'); 
document.close(); 
} 
}, 1000); 
</script> 

이 작동합니다 ''에서 그것을 둘러싸는 시도 자체를 폐쇄입니다 .. :)

관련 문제