select框的text与value值的获取(实用版)

时间:2021-06-22 18:10:56

function def()
{
    var key = document.getElementById ('selectarea'); //select list

var value = document.getElementById ('DocAuthor'); //input text

  //两种不同的取值

value.value = key.options[key.selectedIndex].text; //取得select list已选项的文本(显示给用户的值)赋给input text

value.value = key.options[key.selectedIndex].value; //取得select list已选项的value(正真传递的值)赋给input text
}