开发者

Displaying text as soon as a radio button is clicked, dynamically

I have a bunch of radio buttons. They each correspond to a number from 1 - 24. I want to display that number s开发者_开发知识库omewhere else in the page as soon as a radio button is selected. How would I do this?


Something like this:

<div id="someplace"></div>
<script type="text/javascript">
    function updateText(number) {
        document.getElementById("someplace").innerHTML = number;
    }
</script>
<input value="1" type="radio" onclick="updateText(1)"/>1<br/>
<input value="2" type="radio" onclick="updateText(2)"/>2<br/>
...

If you want to do something more advanced, like not have to put (1) and (2) in each onclick, use something more advanced Jquery.


You create a DIV with the ID "displayNum", with "display:none" style property

Then you create an "onClick" handler to the radio buttons.

The function called from the handler would figure out which button was clicked (from the button's ID) and then change the content of the "displayNum" DIV to the number (using innerHtml property of the DIV), as well as change the "display" property of the DIV from invisible "none" to visible "block".

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜