我做错了,我找不到错误。
我难以理解为什么我不能用这个改变innerHTML ...
我想改变一些文字。<p>Click the button to get your coordinates.</p>
<button onclick="showPosition ()">Use My Location</button>
<!-- TODO: move this to an external script -->
<script>
var targetDiv = document.getElementsByClassName('targetDiv');
function showPosition () {
alert(targetDiv); // alerts the element fine
targetDiv.innerHTML = 'Foo'; // does not work
document.getElementsByClassName('targetDiv').innerHTML = 'foo'; // does not work either.
}
</script>