2014-04-29 4 views
1

innerHTML<input>에 액세스하는 것이 비어있는 이유는 무엇이며이를 수정하려면 어떻게해야합니까?입력 요소의 값에 액세스

Screencast

전체 HTML : 나는 유성을 사용하고

<head> 
    <title>Scientific Calculator</title> 
</head> 

<body> 
    <div class="calculator"> 
    {{> calculator}} 
    </div> 
</body> 

<template name="console"> 
    <input id="console" type="text" value="0" /> 
</template> 

<template name="buttons"> 
    <input type="button" value="7" class="button 7" /> 
    <input type="button" value="8" class="button 8" /> 
    <input type="button" value="9" class="button 9" /> 
    <input type="button" value="A" class="button A" /> 
    <input type="button" value="B" class="button B" /> 
    <input type="button" value="C" class="button C" /> 
    <input type="button" value="4" class="button 4" /> 
    <input type="button" value="5" class="button 5" /> 
    <input type="button" value="6" class="button 6" /> 
    <input type="button" value="A" class="button" /> 
    <input type="button" value="B" class="button" /> 
    <input type="button" value="C" class="button" /> 
    <input type="button" value="1" class="button 1" /> 
    <input type="button" value="2" class="button 2" /> 
    <input type="button" value="3" class="button 3" /> 
    <input type="button" value="A" class="button" /> 
    <input type="button" value="B" class="button" /> 
    <input type="button" value="C" class="button" /> 
    <input type="button" value="0" class="button 0" /> 
</template> 

<template name="adminButtons"> 
</template> 

<template name="calculator"> 
    <!-- make the interface for the Calculator --> 
    {{>console}} 
    {{>buttons}} 
    {{>adminButtons}} 
</template> 

내 응용 프로그램의 스크린 샷이다.

답변

2

innerHTML 필드는 입력 요소 내부의 값을 가져 오는 데 사용되지 않습니다. 대신 value 필드를 사용할 수 있습니다.

그래서, 예를 들어, 당신은

document.getElementById('console').value 

이 ID console와 요소 내부의 텍스트를 얻기 위해 말할 것입니다.

+0

감사! 그 정의되지 않은 라인은 무엇입니까? –

+1

''요소는 빈 요소입니다 (예 : ''이라고 말하면 HTML로 작성한 요소)이므로 내부에 HTML이 없습니다. – APerson

관련 문제