|
【目录】 【上一页】 【下一页】 【索引】
getOptionValue
Returns the text of a selected OPTION in a SELECT form element.
语法
getOptionValue(name, index)
参数
返回
A string containing the text for the selected option, as specified by the associated OPTION tag.
描述
The getOptionValue 函数是一个顶级的服务器端 JavaScript 函数,并不与任何对象关联。 It corresponds to the Option.text property available to client-side JavaScript.
The SELECT tag allows multiple values to be associated with a single form element, with the MULTIPLE attribute. If your application requires select lists that allow multiple selected options, you use the getOptionValue function to get the values of selected options in server-side JavaScript.
示例
Suppose you have the following form element:
<SELECT NAME="what-to-wear" MULTIPLE SIZE=8> <OPTION SELECTED>Jeans <OPTION>Wool Sweater <OPTION SELECTED>Sweatshirt <OPTION SELECTED>Socks <OPTION>Leather Jacket <OPTION>Boots <OPTION>Running Shoes <OPTION>Cape </SELECT>
You could process the input from this select list in server-side JavaScript as follows:
<SERVER> var loopIndex = 0 var loopCount = getOptionValueCount("what-to-wear") // 3 by default while ( loopIndex < loopCount ) { var optionValue = getOptionValue("what-to-wear",loopIndex) write("<br>Item #" + loopIndex + ": " + optionValue + "\n") loopIndex++ } </SERVER>
If the user kept the default selections, this script would return
Item #1: Jeans Item #3: Sweatshirt Item #4: Socks
参看
getOptionValueCount
【目录】 【上一页】 【下一页】 【索引】
|