警报正在显示,但值没有改变....为什么?
<html>
<head>
<title>Test EuDock</title>
</head>
<body >
<label id="labelID">test</label>
<script type="text/javascript" >
document.onkeyup = KeyCheck;
function KeyCheck(e) {
var KeyID = (window.event) ? event.keyCode : e.keyCode;
switch(KeyID)
{
case 39: // right arrow
document.getElementById('labelID').value="BLZ";
alert('ok');
break;
}
}
</script>
</body>
</html>
最佳答案
只有 input
元素具有属性 value
。你要innerHTML
:
document.getElementById('labelID').innerHTML="BLZ";
innerHTML
是唯一的 supported by all browsers 属性.
innerText
is not supported by Firefox和 textContent
is not supported by <= IE8 .
关于javascript - 如何在运行时更改标签值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3737674/