使用<select>值作为javascript var

时间:2017-06-21 15:16:38

标签: javascript html

我试图将段落更改为选定的值。 var char = document.getElementById(“character”)。value; function build(){   document.getElementById(“output”)。innerHTML = char; } &lt; select onchange = build()id = character&gt;                 &lt; option value = dog&gt; dog&lt; / option&gt;                 &lt; option value = cat&gt; cat&lt; / option&gt;                 &lt; option value = moose&gt; moose&lt; / option&gt;             &LT; /选择&GT; &lt; p id = output&gt;#&lt; / p&gt;

1 个答案:

答案 0 :(得分:-1)

我刚修改了你的代码,请查看

&#13;
&#13;
function build(val) {
  console.log(val);
  document.getElementById("output").innerHTML = val;
}
&#13;
<select onchange=build(value) id=character>
                <option value=dog>dog</option>
                <option value=cat>cat</option>
                <option value=moose>moose</option>
            </select>
<p id=output>#</p>
&#13;
&#13;
&#13;