1
我將隨機選擇一個數字,並使用排序後的數字定義選擇的字段。我如何設置領域?如何在JavaScript中設置輸入選擇(HTML)中的字段?
我將隨機選擇一個數字,並使用排序後的數字定義選擇的字段。我如何設置領域?如何在JavaScript中設置輸入選擇(HTML)中的字段?
將選定屬性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"
}
var randomNumber = 3; // just for example
document.getElementById('select_field').selectedIndex = randomNumber;
謝謝合作:d – 2011-05-10 17:56:55