JavaScript手册 
目录
此参考中包含
的内容
轻松上手
简介
操作符
语句
核心
文档
窗口
表单
浏览器
事件和
事件句柄
LiveWire
数据库服务
进程管理服务
实用工具
全局函数
LiveConnect
的Java包
索引
版权
 
【目录】 【上一页】 【下一页】 【索引】

getOptionValue

Returns the text of a selected OPTION in a SELECT form element.

服务器端函数
实现版本LiveWire 1.0

语法

getOptionValue(name, index)

参数

nameA name specified by the NAME attribute of the SELECT tag
index Zero-based ordinal index of the selected option.

返回

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


【目录】 【上一页】 【下一页】 【索引】

回页面顶部