开发者

How to change a label value at runtime?

开发者 https://www.devze.com 2023-01-16 09:41 出处:网络
The alert is showing, but the value is not changing.... why? <html> <head> 开发者_StackOverflow中文版<title>Test EuDock</title>

The alert is showing, but the value is not changing.... why?

<html>
    <head>
 开发者_StackOverflow中文版       <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>


Only input elements have the property value. You want innerHTML :

document.getElementById('labelID').innerHTML="BLZ";

innerHTML is the only attribute that is supported by all browsers.

innerText is not supported by Firefox and textContent is not supported by <= IE8.


I don't think value is a property defined in the DOM for HTML elements. Try assigning to .innerHTML instead, and I think you'll get the result you want.


Try this instead:

document.getElementById('labelID').innerText ="BLZ";


The label element does not have a value property. use document.getElementById('labelID').innerHTML="BLZ"; instead.

0

精彩评论

暂无评论...
验证码 换一张
取 消