0

所以我有一个下拉菜单,在每个菜单列表中都有一个文本..如何让这些文本打印在我的 html 页面的预览部分?

无标题文档

<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>

4

1 回答 1

0

您可以使用此代码。只需复制并粘贴它

<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>
于 2012-10-21T06:24:58.570 回答