0

我有一种情况,即我希望从下拉框中选择的数据显示在其下方的表单(文本类型)内,并且应该是只读的。(使用 html/javascript)。我无法做到这一点,因为我是希望回应的先驱

4

2 回答 2

1

下面是使用下拉菜单中的输入动态更改一个表单框的非 jquery 方法的粗略草图。

<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <script type="text/javascript">
            function optionCallBack (arg) {
                var currentOption = arg.options[arg.selectedIndex].text;
                document.getElementById('changeForm').value = currentOption;
            }
        </script>
    </head>
    <body>
        <select onclick="optionCallBack(this)" id='getForm'>
          <option>asia</option>
          <option>africa</option>
          <option>america</option>
          <option>europe</option>
        </select>
        <form>
            <input value='europe' name='changeForm' id='changeForm'></input>
        </form>
    </body>
</html>
于 2013-07-16T07:29:23.957 回答
0

首先,您需要一个如下所示的选择列表(注意 onchange 事件处理程序)

<select onchange="fillTextBox(this)" id='mySelectList'>
    <option>A</option>
    <option>B</option>
    <option>C</option>
    <option>D</option>
</select>

您还需要一个文本框(让我们给它一个 Id myTextBox

<input value='' name='' id='myTextBox'></input>

您需要以下脚本的fillTextBox功能

function fillTextBox(obj) {
    var sel = obj.value;
    document.getElementById('myTextBox').value = sel;   
}
于 2013-07-16T07:44:03.167 回答