📄 ref_f-g.htm
字号:
<P><I>NAME="formName"</I> specifies the name of the form object.
<P><I>TARGET="windowName"</I> specifies the window that form responses go to. When you submit a form with a TARGET attribute, server responses are displayed in the specified window instead of the window that contains the form. <I>windowName</I> can be an existing window; it can be a frame name specified in a <FRAMESET> tag; or it can be one of the literal frame names _top, _parent, _self, or _blank; it cannot be a JavaScript expression (for example, it cannot be parent<I>.frameName</I> or <I>windowName.frameName</I>). Some values for this attribute may require specific values for other attributes. See <A HREF="tppmsgs/msgs0.htm#3" tppabs="http://www.ics.uci.edu/pub/ietf/htm/rfc1867.txt" TARGET="_top">RFC 1867</A> for details. You can access this value using the target property.
<P><I>ACTION="serverURL"</I> specifies the URL of the server to which form field input information is sent. This attribute can specify a CGI or LiveWire application on the server; it can also be a mailto: URL if the form is to be mailed. See the <A HREF="ref_h-l.htm#location_object" tppabs="http://www.nease.net/~jim/ref_h-l.htm#location_object">location</A> object for a 描述 of the URL components. Some values for this attribute may require specific values for other attributes. See <A HREF="tppmsgs/msgs0.htm#3" tppabs="http://www.ics.uci.edu/pub/ietf/htm/rfc1867.txt" TARGET="_top">RFC 1867</A> for details. You can access this value using the action property.
<P><I>METHOD=GET | POST</I> specifies how information is sent to the server specified by <I>ACTION</I>. GET (the default) appends the input information to the URL which on most receiving systems becomes the value of the environment variable <I>QUERY_STRING</I>. POST sends the input information in a data body which is available on <I>stdin</I> with the data length set in the environment variable <I>CONTENT_LENGTH</I>. Some values for this attribute may require specific values for other attributes. See <A HREF="tppmsgs/msgs0.htm#3" tppabs="http://www.ics.uci.edu/pub/ietf/htm/rfc1867.txt" TARGET="_top">RFC 1867</A> for details. You can access this value using the method property.
<P><I>ENCTYPE="encodingType"</I> specifies the MIME encoding of the data sent: "application/x-www-form-urlencoded" (the default) or "multipart/form-data". Some values for this attribute may require specific values for other attributes. See <A HREF="tppmsgs/msgs0.htm#3" tppabs="http://www.ics.uci.edu/pub/ietf/htm/rfc1867.txt" TARGET="_top">RFC 1867</A> for details. You can access this value using the encoding property.
<P>To use a form object's properties and methods:
<PRE>
1. <I>formName</I>.<I>propertyName</I>
2. <I>formName</I>.<I>methodName</I>(<I>parameters</I>)
3. forms[<I>index</I>].<I>propertyName</I>
4. forms[<I>index</I>].<I>methodName</I>(<I>parameters</I>)
</PRE>
<I>formName</I> is the value of the NAME attribute of a form object.
<BR><I>propertyName</I> is one of the properties listed below.
<BR><I>methodName</I> is one of the methods listed below.
<BR><I>index</I> is an integer representing a form object.
<H3>Property of</H3>
<LI><A HREF="ref_d-e.htm#document_object" tppabs="http://www.nease.net/~jim/ref_d-e.htm#document_object">document</A>
<H3>描述</H3>
<P>Each form in a document is a distinct object.
<P>You can reference a form's elements in your code by using the element's name (from the NAME attribute) or the <A HREF="ref_d-e.htm#elements_object" tppabs="http://www.nease.net/~jim/ref_d-e.htm#elements_object"><I>elements</I></A> array. The <I>elements</I> array contains an entry for each element (such as a checkbox, radio, or text object) in a form.
<H4>The <I>forms</I> array</H4>
<P>You can reference the forms in your code by using the <I>forms</I> array (you can also use the form name). This array contains an entry for each form object (<FORM> tag) in a document in source order. For example, if a document contains three forms, these forms are reflected as <TT>document.forms[0]</TT>, <TT>document.forms[1]</TT>, and <TT>document.forms[2]</TT>.
<P>To use the <I>forms</I> array:
<PRE>
1. document.forms[<I>index</I>]
2. document.forms.length
</PRE>
<P><I>index</I> is an integer representing a form in a document.
<P>To obtain the number of forms in a document, use the length property: <TT>document.forms.length</TT>.
<P>You can also refer to a form's elements by using the <I>forms</I> array. For example, you would refer to a text object named <I>quantity</I> in the second form as <TT>document.forms[1].quantity</TT>. You would refer to the value property of this text object as <TT>document.forms[1].quantity.value</TT>.
<P>Elements in the <I>forms</I> array are read-only. For example, the statement <TT>document.forms[0]="music"</TT> has no effect.
<P>The value of each element in the <I>forms</I> array is <TT><object <I>nameAttribute</I>></TT>, where <I>nameAttribute</I> is the NAME attribute of the form.
<H3>Properties</H3>
<P>The form object has the following properties:
<LI><A HREF="ref_a-c.htm#action_property" tppabs="http://www.nease.net/~jim/ref_a-c.htm#action_property">action</A> reflects the ACTION attribute
<LI><A HREF="ref_d-e.htm#elements_object" tppabs="http://www.nease.net/~jim/ref_d-e.htm#elements_object">elements</A> is an array reflecting all the elements in a form
<LI><A HREF="ref_d-e.htm#encoding_property" tppabs="http://www.nease.net/~jim/ref_d-e.htm#encoding_property">encoding</A> reflects the ENCTYPE attribute
<LI><A HREF="ref_h-l.htm#length_property" tppabs="http://www.nease.net/~jim/ref_h-l.htm#length_property">length</A> reflects the number of elements on a form
<LI><A HREF="ref_m-q.htm#method_property" tppabs="http://www.nease.net/~jim/ref_m-q.htm#method_property">method</A> reflects the METHOD attribute
<LI><A HREF="ref_t-z.htm#target_property" tppabs="http://www.nease.net/~jim/ref_t-z.htm#target_property">target</A> reflects the TARGET attribute
<P>The following objects are also properties of the form object:
<LI><A HREF="ref_a-c.htm#button_object" tppabs="http://www.nease.net/~jim/ref_a-c.htm#button_object">button</A>
<LI><A HREF="ref_a-c.htm#checkbox_object" tppabs="http://www.nease.net/~jim/ref_a-c.htm#checkbox_object">checkbox</A>
<LI><A HREF="ref_h-l.htm#hidden_object" tppabs="http://www.nease.net/~jim/ref_h-l.htm#hidden_object">hidden</A>
<LI><A HREF="ref_m-q.htm#password_object" tppabs="http://www.nease.net/~jim/ref_m-q.htm#password_object">password</A>
<LI><A HREF="ref_r-r.htm#radio_object" tppabs="http://www.nease.net/~jim/ref_r-r.htm#radio_object">radio</A>
<LI><A HREF="ref_r-r.htm#reset_object" tppabs="http://www.nease.net/~jim/ref_r-r.htm#reset_object">reset</A>
<LI><A HREF="ref_s-s.htm#select_object" tppabs="http://www.nease.net/~jim/ref_s-s.htm#select_object">select</A>
<LI><A HREF="ref_s-s.htm#submit_object" tppabs="http://www.nease.net/~jim/ref_s-s.htm#submit_object">submit</A>
<LI><A HREF="ref_t-z.htm#text_object" tppabs="http://www.nease.net/~jim/ref_t-z.htm#text_object">text</A>
<LI><A HREF="ref_t-z.htm#textarea_object" tppabs="http://www.nease.net/~jim/ref_t-z.htm#textarea_object">textarea</A>
<P>The <I>forms</I> array has the following properties:
<LI><A HREF="ref_h-l.htm#length_property" tppabs="http://www.nease.net/~jim/ref_h-l.htm#length_property">length</A> reflects the number of forms in a document
<H3>Methods</H3>
<LI><A HREF="ref_s-s.htm#submit_method" tppabs="http://www.nease.net/~jim/ref_s-s.htm#submit_method">submit</A>
<H3>Event handlers</H3>
<LI><A HREF="ref_m-q.htm#onSubmit_event" tppabs="http://www.nease.net/~jim/ref_m-q.htm#onSubmit_event">onSubmit</A>
<H3>例子</H3>
<P><B>Example 1: named form.</B> The following example creates a form called <I>form1</I> that contains text fields for first name and last name. The form also contains two buttons that change the names to all upper case or all lower case. The function <I>setCase</I> shows how to refer to the form by its name.
<XMP>
<htm>
<HEAD>
<TITLE>Form object example</TITLE>
</HEAD>
<SCRIPT>
function setCase (caseSpec){
if (caseSpec == "upper") {
document.form1.firstName.value=document.form1.firstName.value.toUpperCase()
document.form1.lastName.value=document.form1.lastName.value.toUpperCase()}
else {
document.form1.firstName.value=document.form1.firstName.value.toLowerCase()
document.form1.lastName.value=document.form1.lastName.value.toLowerCase()}
}
</SCRIPT>
<BODY>
<FORM NAME="form1">
<B>First name:</B>
<INPUT TYPE="text" NAME="firstName" SIZE=20>
<BR><B>Last name:</B>
<INPUT TYPE="text" NAME="lastName" SIZE=20>
<P><INPUT TYPE="button" VALUE="Names to uppercase" NAME="upperButton"
onClick="setCase('upper')">
<INPUT TYPE="button" VALUE="Names to lowercase" NAME="lowerButton"
onClick="setCase('lower')">
</FORM>
</BODY>
</htm>
</XMP>
<B>Example 2: <I>forms</I> array.</B> The onLoad event handler in the following example displays the name of the first form in an alert dialog box.
<XMP>
<BODY onLoad="alert('You are looking at the ' + document.forms[0] + ' form!')">
</XMP>
<P>If the form name is <I>musicType</I>, the alert displays the following message:
<XMP>
You are looking at the <object musicType> form!
</XMP>
<P><B>Example 3: onSubmit event handler.</B> The following example shows an onSubmit event handler that determines whether to submit a form. The form contains one text object where the user enters three characters. The onSubmit event handler calls a function, <I>checkData</I>, that returns true if the number of characters is three; otherwise, it returns false. Notice that the form's onSubmit event handler, not the submit button's onClick event handler, calls the <I>checkData</I> function. Also, the onSubmit event handler contains a <B>return</B> statement that returns the value obtained with the function call.
<XMP>
<htm>
<HEAD>
<TITLE>Form object/onSubmit event handler example</TITLE>
<TITLE>Form object example</TITLE>
</HEAD>
<SCRIPT>
var dataOK=false
function checkData (){
if (document.form1.threeChar.value.length == 3) {
return true}
else {
alert("Enter exactly three characters. " + document.form1.threeChar.value + " is not valid.")
return false}
}
</SCRIPT>
<BODY>
<FORM NAME="form1" onSubmit="return checkData()">
<B>Enter 3 characters:</B>
<INPUT TYPE="text" NAME="threeChar" SIZE=3>
<P><INPUT TYPE="submit" VALUE="Done" NAME="submit1"
onClick="document.form1.threeChar.value=document.form1.threeChar.value.toUpperCase()">
</FORM>
</BODY>
</htm>
</XMP>
<P><B>Example 4: submit method.</B> The following example is similar to the previous one, except it submits the form using the submit method instead of a submit object. The form's onSubmit event handler does not prevent the form from being submitted. The form uses a button's onClick event handler to call the <I>checkData</I> function. If the value is valid, the <I>checkData</I> function submits the form by calling the form's submit method.
<XMP>
<htm>
<HEAD>
<TITLE>Form object/submit method example</TITLE>
</HEAD>
<SCRIPT>
var dataOK=false
function checkData (){
if (document.form1.threeChar.value.length == 3) {
document.form1.submit()}
else {
alert("Enter exactly three characters. " + document.form1.threeChar.value + " is not valid.")
return false}
}
</SCRIPT>
<BODY>
<FORM NAME="form1" onSubmit="alert('Form is being submitted.')">
<B>Enter 3 characters:</B>
<INPUT TYPE="text" NAME="threeChar" SIZE=3>
<P><INPUT TYPE="button" VALUE="Done" NAME="button1"
onClick="checkData()">
</FORM>
</BODY>
</htm>
</XMP>
<H3>相关</H3>
<LI><A HREF="ref_a-c.htm#button_object" tppabs="http://www.nease.net/~jim/ref_a-c.htm#button_object">button</A>, <A HREF="ref_a-c.htm#checkbox_object" tppabs="http://www.nease.net/~jim/ref_a-c.htm#checkbox_object">checkbox</A>, <A HREF="ref_h-l.htm#hidden_object" tppabs="http://www.nease.net/~jim/ref_h-l.htm#hidden_object">hidden</A>, <A HREF="ref_m-q.htm#password_object" tppabs="http://www.nease.net/~jim/ref_m-q.htm#password_object">password</A>, <A HREF="ref_r-r.htm#radio_object" tppabs="http://www.nease.net/~jim/ref_r-r.htm#radio_object">radio</A>, <A HREF="ref_r-r.htm#reset_object" tppabs="http://www.nease.net/~jim/ref_r-r.htm#reset_object">reset</A>, <A HREF="ref_s-s.htm#select_object" tppabs="http://www.nease.net/~jim/ref_s-s.htm#select_object">select</A>, <A HREF="ref_s-s.htm#submit_object" tppabs="http://www.nease.net/~jim/ref_s-s.htm#submit_object">submit</A>, <A HREF="ref_t-z.htm#text_object" tppabs="http://www.nease.net/~jim/ref_t-z.htm#text_object">text</A>, <A HREF="ref_t-z.htm#textarea_object" tppabs="http://www.nease.net/~jim/ref_t-z.htm#textarea_object">textarea </A> objects
<!------------------------------------------------------------------------------------------------->
<HR>
<A NAME="forms_property"><H2>forms property</H2></A>
<P>An array of objects corresponding to the forms (<FORM> tags) in a document in source order. See <A HREF="ref_f-g.htm#form_object" tppabs="http://www.nease.net/~jim/ref_f-g.htm#form_object">form</A> object.
<!------------------------------------------------------------------------------------------------->
<HR>
<A NAME="forward_method"><H2>forward method</H2></A>
<P>
Loads the next URL in the history list.
<H3>语法</H3>
<PRE>history.forward()</PRE>
<H3>方法</H3>
<P><A HREF="ref_h-l.htm#history_object" tppabs="http://www.nease.net/~jim/ref_h-l.htm#history_object">history</A>
<H3>描述</H3>
<P>This method performs the same action as a user choosing the Forward button in the Navigator. The forward method is the same as <TT>history.go(1)</TT>.
<H3>例子</H3>
The following custom buttons perform the same operations as the Navigator Back and Forward buttons:
<PRE>
<P><INPUT TYPE="button" VALUE="< Back"
onClick="history.back()">
<P><INPUT TYPE="button" VALUE="> Forward"
onClick="history.forward()">
</PRE>
<H3>相关</H3>
<LI><A HREF="ref_a-c.htm#back_method" tppabs="http://www.nease.net/~jim/ref_a-c.htm#back_method">back</A>, <A HREF="ref_f-g.htm#go_method" tppabs="http://www.nease.net/~jim/ref_f-g.htm#go_method">go</A> methods
<!------------------------------------------------------------------------------------------------>
<HR>
<A NAME="frame_object"><H2>frame object (<I>frames</I> array)</H2></A>
<P>A window that can display multiple, independently scrollable frames on a single screen, each with its own distinct URL. Frames can point to different URLs and be targeted by other URLs, all within the same screen. A series of frames makes up a page.
<H3>语法</H3>
<P>To define a frame object, use standard htm 语法. The onLoad and onUnload event handlers are specified in the <FRAMESET> tag but are actually event handlers for the window object:
<PRE>
<FRAMESET
ROWS="<I>rowHeightList</I>"
COLS="<I>columnWidthList</I>"
[onLoad="<I>handlerText</I>"]
[onUnload="<I>handlerText</I>"]>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -