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

Hidden

A Text object that is suppressed from form display on an HTML form. A Hidden object is used for passing name/value pairs when a form submits.

客户端对象
实现版本Navigator 2.0
Navigator 3.0: 添加了 type 属性

创建源

The HTML INPUT tag, with "hidden" as the value of the TYPE attribute. For a given form, the JavaScript runtime engine creates appropriate Hidden objects and puts these objects in the elements array of the corresponding Form object. You access a Hidden object by indexing this array. You can index the array either by number or, if supplied, by using the value of the NAME attribute.

描述

A Hidden object is a form element and must be defined within a FORM tag.

A Hidden object cannot be seen or modified by an end user, but you can programmatically change the value of the object by changing its value property. You can use Hidden objects for client/server communication.

属性概览

formSpecifies the form containing the Hidden object.
nameReflects the NAME attribute.
typeReflects the TYPE attribute.
valueReflects the current value of the Hidden object.

示例

The following example uses a Hidden object to store the value of the last object the user clicked. The form contains a "Display hidden value" button that the user can click to display the value of the Hidden object in an Alert dialog box.

<HTML>
<HEAD>
<TITLE>Hidden object example</TITLE>
</HEAD>
<BODY>
<B>Click some of these objects, then click the "Display value" button
<BR>to see the value of the last object clicked.</B>
<FORM NAME="myForm">
<INPUT TYPE="hidden" NAME="hiddenObject" VALUE="无">
<P>
<INPUT TYPE="button" VALUE="Click me" NAME="button1"
   onClick="document.myForm.hiddenObject.value=this.value">
<P>
<INPUT TYPE="radio" NAME="musicChoice" VALUE="soul-and-r&b"
   onClick="document.myForm.hiddenObject.value=this.value"> Soul and R&B
<INPUT TYPE="radio" NAME="musicChoice" VALUE="jazz"
   onClick="document.myForm.hiddenObject.value=this.value"> Jazz
<INPUT TYPE="radio" NAME="musicChoice" VALUE="classical"
   onClick="document.myForm.hiddenObject.value=this.value"> Classical
<P>
<SELECT NAME="music_type_single"
   onFocus="document.myForm.hiddenObject.value=this.options[this.selectedIndex].text">
   <OPTION SELECTED> Red <OPTION> Orange <OPTION> Yellow
</SELECT>
<P><INPUT TYPE="button" VALUE="Display hidden value" NAME="button2"
   onClick="alert('Last object clicked: ' + document.myForm.hiddenObject.value)">
</FORM>
</BODY>
</HTML>

参看

document.cookie

属性

form

An object reference specifying the form containing this object.

方法源Hidden
只读
实现版本Navigator 2.0

描述

每个表单元素都有一个 form 属性用于指向元素的父表单。该属性在事件控制句柄中特别有用,你可能想要由其获得当前表单中其它元素。

示例

示例 1. In the following example, the form myForm contains a Hidden object and a button. When the user clicks the button, the value of the Hidden object is set to the form's name. The button's onClick event handler uses this.form to refer to the parent form, myForm.

<FORM NAME="myForm">
Form name:<INPUT TYPE="hidden" NAME="h1" VALUE="Beluga">
<P>
<INPUT NAME="button1" TYPE="button" VALUE="Store Form Name"
   onClick="this.form.h1.value=this.form.name">
</FORM>
示例 2. The following example uses an object reference, rather than the this keyword, to refer to a form. The code returns a reference to myForm, which is a form containing myHiddenObject.

document.myForm.myHiddenObject.form

参看

Form

name

A string specifying the name of this object.

方法源Hidden
实现版本Navigator 2.0

安全性

Navigator 3.0:该属性默认是带有污点的。有关数据污点的更多信息,请看“JavaScript 的安全性”

type

For all Hidden objects, the value of the type property is "hidden". This property specifies the form element's type.

方法源Hidden
只读
实现版本Navigator 3.0

示例

The following example writes the value of the type property for every element on a form.

for (var i = 0; i < document.myForm.elements.length; i++) {
   document.writeln("<BR>type is " + document.myForm.elements[i].type)
}

value

A string that reflects the VALUE attribute of the object.

方法源Hidden
实现版本Navigator 2.0

安全性

Navigator 3.0:该属性默认是带有污点的。有关数据污点的更多信息,请看“JavaScript 的安全性”

示例

The following function evaluates the value property of a group of buttons and displays it in the msgWindow window:

function valueGetter() {
   var msgWindow=window.open("")
   msgWindow.document.write("The submit button says " +
      document.valueTest.submitButton.value + "<BR>")
   msgWindow.document.write("The reset button says " +
      document.valueTest.resetButton.value + "<BR>")
   msgWindow.document.write("The hidden field says " +
      document.valueTest.hiddenField.value + "<BR>")
   msgWindow.document.close()
}
This example displays the following values:

The submit button says Query Submit
The reset button says Reset
The hidden field says pipefish are cute.
The previous example assumes the buttons have been defined as follows:

<INPUT TYPE="submit" NAME="submitButton">
<INPUT TYPE="reset" NAME="resetButton">
<INPUT TYPE="hidden" NAME="hiddenField" VALUE="pipefish are cute.">


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

回页面顶部回页面顶部