如何使用javascript在输入选择(HTML)中设置a字段?

如何使用javascript在输入选择(HTML)中设置a字段?,javascript,html,select,field,Javascript,Html,Select,Field,我将随机选择一个数字,并用排序后的数字在select中定义所选字段。如何设置字段?将属性selected=“selected”添加到要选择的选项元素中 伪代码 function foo() { create list of option elements generate random number get a single option element at index of random number set all options attribute "selected" = null s

我将随机选择一个数字,并用排序后的数字在select中定义所选字段。如何设置字段?

将属性selected=“selected”添加到要选择的选项元素中

伪代码

function foo()
{
create list of option elements
generate random number
get a single option element at index of random number
set all options attribute "selected" = null
set the option element[at index of random number] attribute selected = "selected"
}

将属性selected=“selected”添加到要选择的选项元素中

伪代码

function foo()
{
create list of option elements
generate random number
get a single option element at index of random number
set all options attribute "selected" = null
set the option element[at index of random number] attribute selected = "selected"
}