为什么访问 innerHTML
的 <input>
返回空白,我需要做什么才能修复它?
这是我的应用程序的屏幕截图:
完整的 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>
我正在使用 Meteor。
最佳答案
innerHTML
字段不用于获取输入元素内的值;相反,您可以使用 value
字段。
所以,例如,你会说
document.getElementById('console').value
获取 ID 为 console
的元素内的文本。
关于javascript - 访问输入元素中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23369929/