📄 ref_f-g.htm
字号:
<LI><A HREF="ref_t-z.htm#textarea_object" textarea_object">textarea</A>
<P>The <I>forms</I> array has the following properties:
<LI><A HREF="ref_h-l.htm#length_property" length_property">length</A> reflects the number of forms in a document
<H3>Methods</H3>
<LI><A HREF="ref_s-s.htm#submit_method" submit_method">submit</A>
<H3>Event handlers</H3>
<LI><A HREF="ref_m-q.htm#onSubmit_event" 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" button_object">button</A>, <A HREF="ref_a-c.htm#checkbox_object" checkbox_object">checkbox</A>, <A HREF="ref_h-l.htm#hidden_object" hidden_object">hidden</A>, <A HREF="ref_m-q.htm#password_object" password_object">password</A>, <A HREF="ref_r-r.htm#radio_object" radio_object">radio</A>, <A HREF="ref_r-r.htm#reset_object" reset_object">reset</A>, <A HREF="ref_s-s.htm#select_object" select_object">select</A>, <A HREF="ref_s-s.htm#submit_object" submit_object">submit</A>, <A HREF="ref_t-z.htm#text_object" text_object">text</A>, <A HREF="ref_t-z.htm#textarea_object" 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" 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" 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" back_method">back</A>, <A HREF="ref_f-g.htm#go_method" 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>"]>
[<FRAME SRC="<I>locationOrURL</I>" NAME="<I>frameName</I>">]
</FRAMESET>
</PRE>
<I>ROWS="rowHeightList"</I> is a comma-separated list of values specifying the row-height of the frame. An optional suffix defines the units. Default units are pixels.
<BR><I>COLS="columnWidthList"</I> is a comma-separated list of values specifying the column-width of the frame. An optional suffix defines the units. Default units are pixels.
<BR><I><FRAME></I> defines a frame.
<BR><I>SRC="locationOrURL"</I> specifies the URL of the document to be displayed in the frame. The URL cannot include an anchor name; for example <TT><FRAME SRC="doc2.htm#colors" NAME="frame2"></TT> is invalid. See the <A HREF="ref_h-l.htm#location_object" location_object">location</A> object for a 描述 of the URL components.
<BR><I>NAME="frameName"</I> specifies a name to be used as a target of hyperlink jumps.
<P>To use a frame object's properties:
<PRE>
1. [<I>windowReference</I>.]<I>frameName</I>.<I>propertyName</I>
2. [<I>windowReference</I>.]frames[<I>index</I>].<I>propertyName</I>
3. window.<I>propertyName</I>
4. self.<I>propertyName</I>
5. parent.<I>propertyName</I>
</PRE>
<I>windowReference</I> is a variable <I>windowVar</I> from a window definition (see <A HREF="ref_t-z.htm#window_object" window_object">window</A> object), or one of the synonyms top or parent.
<BR><I>frameName</I> is the value of the NAME attribute in the <FRAME> tag of a frame object.
<BR><I>index</I> is an integer representing a frame object.
<BR><I>propertyName</I> is one of the properties listed below.
<H3>Property of</H3>
<LI>The frame object is a property of <A HREF="ref_t-z.htm#window_object" window_object">window</A>
<LI>The frames array is a property of both <A HREF="ref_f-g.htm#frame_object" frame_object">frame</A> and <A HREF="ref_t-z.htm#window_object" window_object">window</A>
<H3>描述</H3>
<P>The <FRAMESET> tag is used in an htm document whose sole purpose is to define the layout of frames that make up a page. Each frame is a window object.
<P>If a <FRAME> tag contains SRC and NAME attributes, you can refer to that frame from a sibling frame by using <TT>parent.<I>frameName</I></TT> or <TT>parent.frames[<I>index</I>]</TT>. For example, if the fourth frame in a set has NAME="homeFrame", sibling frames can refer to that frame using <TT>parent.homeFrame</TT> or <TT>parent.frames[3]</TT>.
<P>The self and window properties are synonyms for the current frame, and you can optionally use them to refer to the current frame. You can use these properties to make your code more readable. See the properties listed below for 例子.
<P>The top and parent properties are also synonyms that can be used in place of the frame name. top refers to the top-most window that contains frames or nested framesets, and parent refers to the window containing the current frameset. See the <A HREF="ref_t-z.htm#top_property" top_property">top</A> and <A HREF="ref_m-q.htm#parent_property" parent_property">parent</A> properties.
<H4>The <I>frames</I> array</H4>
<P>You can reference the frame objects in your code by using the <I>frames</I> array. This array contains an entry for each child frame (<FRAME> tag) in a window containing a <FRAMESET> tag in source order. For example, if a window contains three child frames, these frames are reflected as <TT>parent.frames[0]</TT>, <TT>parent.frames[1]</TT>, and <TT>parent.frames[2]</TT>.
<P>To use the <I>frames</I> array:
<PRE>
1. [<I>frameReference</I>.]frames[<I>index</I>]
2. [<I>frameReference</I>.]frames.length
3. [<I>windowReference</I>.]frames[<I>index</I>]
4. [<I>windowReference</I>.]frames.length
</PRE>
<P><I>frameReference</I> is a valid way of referring to a frame, as described in the <A HREF="ref_f-g.htm#frame_object" frame_object">frame</A> object.
<BR><I>windowReference</I> is a variable <I>windowVar</I> from a window definition (see <A HREF="ref_t-z.htm#window_object" window_object">window</A> object), or one of the synonyms top or parent.
<BR><I>index</I> is an integer representing a frame in a parent window.
<P>To obtain the number of child frames in a window or frame, use the length property:
<PRE>
[<I>windowReference</I>.].frames.length
[<I>frameReference</I>.].frames.length
</PRE>
<P>Elements in the <I>frames</I> array are read-only. For example, the statement <TT><I>windowReference</I>.frames[0]="frame1"</TT> has no effect.
<P>The value of each element in the <I>frames</I> array is <TT><object <I>nameAttribute</I>></TT>, where <I>nameAttribute</I> is the NAME attribute of the frame.
<H3>Properties</H3>
<P>The frame object has the following properties:
<LI><A HREF="ref_f-g.htm#frame_object" frame_object">frames</A> is an array reflecting all the frames in a window
<LI><A HREF="ref_m-q.htm#name_property" name_property">name</A> reflects the NAME attribute of the <FRAME> tag
<LI><A HREF="ref_h-l.htm#length_property" length_property">length</A> reflects the number of child frames within a frame
<LI><A HREF="ref_m-q.htm#parent_property" parent_property">parent</A> is a synonym for the window or frame containing the current frameset
<LI><A HREF="ref_s-s.htm#self_property" self_property">self</A> is a synonym for the current frame
<LI><A HREF="ref_t-z.htm#window_property" window_property">window</A> is a synonym for the current frame
<P>The <I>frames</I> array has the following properties:
<LI><A HREF="ref_h-l.htm#length_property" length_property">length</A> reflects the number of child frames within a frame
<H3>Methods</H3>
<LI><A HREF="ref_a-c.htm#clearTimeout_method" clearTimeout_method">clearTimeout</A>
<LI><A HREF="ref_s-s.htm#setTimeout_method" setTimeout_method">setTimeout</A>
<H3>Event handlers</H3>
<LI>None. The onLoad and onUnload event handlers are specified in the <FRAMESET> tag but are actually event handlers for the window object.
<H3>例子</H3>
<P>The following example creates two windows, each with four frames. In the first window, the first frame contains pushbuttons that change the background colors of the frames in both windows.
<P>FRAMSET1.htm, which defines the frames for the first window, contains the following code:
<XMP>
<htm>
<HEAD>
<TITLE>Frames and Framesets: Window 1</TITLE>
</HEAD>
<FRAMESET ROWS="50%,50%" COLS="40%,60%" onLoad="alert('Hello, World.')">
<FRAME SRC="tppmsgs/msgs0.htm#13" tppabs="http://www.nease.net/~jim/framcon1.htm" NAME="frame1">
<FRAME SRC="tppmsgs/msgs0.htm#14" tppabs="http://www.nease.net/~jim/framcon2.htm" NAME="frame2">
<FRAME SRC="tppmsgs/msgs0.htm#14" tppabs="http://www.nease.net/~jim/framcon2.htm" NAME="frame3">
<FRAME SRC="tppmsgs/msgs0.htm#14" tppabs="http://www.nease.net/~jim/framcon2.htm" NAME="frame4">
</FRAMESET>
</htm>
</XMP>
<P>FRAMSET2.htm, which defines the frames for the second window, contains the following code:
<XMP>
<htm>
<HEAD>
<TITLE>Frames and Framesets: Window 2</TITLE>
</HEAD>
<FRAMESET ROWS="50%,50%" COLS="40%,60%">
<FRAME SRC="tppmsgs/msgs0.htm#14" tppabs="http://www.nease.net/~jim/framcon2.htm" NAME="frame1">
<FRAME SRC="tppmsgs/msgs0.htm#14" tppabs="http://www.nease.net/~jim/framcon2.htm" NAME="frame2">
<FRAME SRC="tppmsgs/msgs0.htm#14" tppabs="http://www.nease.net/~jim/framcon2.htm" NAME="frame3">
<FRAME SRC="tppmsgs/msgs0.htm#14" tppabs="http://www.nease.net/~jim/framcon2.htm" NAME="frame4">
</FRAMESET>
</htm>
</XMP>
<P>FRAMCON1.htm, which defines the content for the first frame in the first window, contains the following code:
<XMP>
<htm>
<BODY>
<A NAME="frame1"><H1>Frame1</H1></A>
<P><A HREF="tppmsgs/msgs0.htm#15" tppabs="http://www.nease.net/~jim/framcon3.htm" target=frame2>Click here</A> to load a different file into frame 2.
<SCRIPT>
window2=open("framset2.htm","secondFrameset")
</SCRIPT>
<FORM>
<P><INPUT TYPE="button" VALUE="Change frame2 to teal"
onClick="parent.frame2.document.bgColor='teal'">
<P><INPUT TYPE="button" VALUE="Change frame3 to slateblue"
onClick="parent.frames[2].document.bgColor='slateblue'">
<P><INPUT TYPE="button" VALUE="Change frame4 to darkturquoise"
onClick="top.frames[3].document.bgColor='darkturquoise'">
<P><INPUT TYPE="button" VALUE="window2.frame2 to violet"
onClick="window2.frame2.document.bgColor='violet'">
<P><INPUT TYPE="button" VALUE="window2.frame3 to fuchsia"
onClick="window2.frames[2].document.bgColor='fuchsia'">
<P><INPUT TYPE="button" VALUE="window2.frame4 to deeppink"
onClick="window2.frames[3].document.bgColor='deeppink'">
</FORM>
</BODY>
</htm>
</XMP>
<P>FRAMCON2.htm, which defines the content for the remaining frames, contains the following code:
<XMP>
<htm>
<BODY>
<P>This is a frame.
</BODY>
</htm>
</XMP>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -