简体   繁体   English

如何使下拉菜单中的文本出现在html部分?

[英]how to make the text inside the drop down menu appear on the section of html?

So i have a drop down menu, in each of the menu list there is a text .. how to do i get those text to print out on preview section of my html page? 所以我有一个下拉菜单,在每个菜单列表中都有一个文本..我该如何获取这些文本以在html页面的预览部分中打印出来?

Untitled Document 无标题文档

<body>
    <h1>Word</h1>

    <div id="controls">
        <fieldset id="text">
            <legend>Preview text</legend>
            <ul>
                <li>
                    <label><input type="radio" name="cc" value="Pre" id="pre" checked="checked" /> Pre: </label>
                    <select name ="dropdown">
                        <option selected="selected">Hello World.</option>
                        <option>How is your days going?.</option>
                        <option>I <3 You.</option>
                    </select>
                </li>

            </ul>
        </fieldset>
    <div id="preview">
        <fieldset>
            <legend>Preview</legend>
            <p></p>
        </fieldset>
    </div>
</body>

you can use this code.just copy and paste it 您可以使用此代码。只需复制并粘贴

<script type="text/javascript">
function fnc()
{
var text=document.getElementById("dropdown").value;
document.getElementById("preview").innerHTML=text;
}
</script>
<body>
<h1>Word</h1>

<div id="controls">
    <fieldset id="text">
        <legend>Preview text</legend>
        <ul>
            <li>
                <label><input type="radio" name="cc" value="Pre" id="pre" checked="checked" /> Pre: </label>
                <select name ="dropdown" onchange="fnc()" id="dropdown">
                    <option selected="selected">Hello World.</option>
                    <option>How is your days going?.</option>
                    <option>I <3 You.</option>
                </select>
            </li>

        </ul>
    </fieldset>
    <div id="preview">
    <fieldset>
        <legend>Preview</legend>
        <p></p>
    </fieldset>
    </div>
</body>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM