⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ref_t-z.htm

📁 javascript函数大全HTML javascript函数大全HTML
💻 HTM
📖 第 1 页 / 共 4 页
字号:
 4. self.<I>methodName</I>(<I>parameters</I>)
 5. top.<I>propertyName</I>
 6. top.<I>methodName</I>(<I>parameters</I>)
 7. parent.<I>propertyName</I>
 8. parent.<I>methodName</I>(<I>parameters</I>)
 9. <I>windowVar</I>.<I>propertyName</I>
10. <I>windowVar</I>.<I>methodName</I>(<I>parameters</I>)
11. <I>propertyName</I>
12. <I>methodName</I>(<I>parameters</I>)
</PRE>
<I>windowVar</I> is a variable referring to a window object. See the preceding 语法 for defining a window.
<BR><I>propertyName</I> is one of the properties listed below.
<BR><I>methodName</I> is one of the methods listed below.

<P>To define an onLoad or onUnload event handler for a window object, use the &LTBODY&GT or &LTFRAMESET&GT tags:
<PRE>
&LTBODY
   ...
   [onLoad="<I>handlerText</I>"]
   [onUnload="<I>handlerText</I>"]&GT
&LT/BODY&GT

&LTFRAMESET
   ROWS="<I>rowHeightList</I>"
   COLS="<I>columnWidthList</I>"
   [onLoad="<I>handlerText</I>"]
   [onUnload="<I>handlerText</I>"]&GT
   [&LTFRAME SRC="<I>locationOrURL</I>" NAME="<I>frameName</I>"&GT]
&LT/FRAMESET&GT
</PRE>

<P>For information on the &LTBODY&GT and &LTFRAMESET&GT tags, see the <A HREF="ref_d-e.htm#document_object" document_object">document</A> and <A HREF="ref_f-g.htm#frame_object" frame_object">frame</A> objects.


<H3>Property of</H3>
<LI>None.


<H3>描述</H3>
<P>The window object is the top-level object in the JavaScript client hierarchy. Frame objects are also windows.

<P>The self and window properties are synonyms for the current window, and you can optionally use them to refer to the current window. For example, you can close the current window by calling either <TT>window.close()</TT> or <TT>self.close()</TT>. You can use these properties to make your code more readable, or to disambiguate the property reference <TT>self.status</TT> from a form called <TT>status</TT>. See the properties and methods listed below for more 例子.

<P>The top and parent properties are also synonyms that can be used in place of the window name. top refers to the top-most Navigator window, and parent refers to a window containing a 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.

<P>Because the existence of the current window is assumed, you do not have to reference the name of the window when you call its methods and assign its properties. For example, <TT>status="Jump to a new location"</TT> is a valid property assignment, and <TT>close()</TT> is a valid method call. However, when you open or close a window within an event handler, you must specify window.open() or window.close() instead of simply using open() or close(). Due to the scoping of static objects in JavaScript, a call to close() without specifying an object name is equivalent to document.close().

<P>You can reference a window's frame objects in your code by using the frames array. The frames array contains an entry for each frame in a window with a &LTFRAMESET&GT tag.

<P>Windows lack event handlers until some htm is loaded into them containing a &LTBODY&GT or &LTFRAMESET&GT tag.


<H3>Properties</H3>
<LI><A HREF="ref_d-e.htm#defaultStatus_property" defaultStatus_property">defaultStatus</A> reflects the default message displayed in the window's status bar
<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_h-l.htm#length_property" length_property">length</A> reflects the number of frames in a parent window
<LI><A HREF="ref_m-q.htm#name_property" name_property">name</A> reflects the <I>windowName</I> argument
<LI><A HREF="ref_m-q.htm#parent_property" parent_property">parent</A> is a synonym for the <I>windowName</I> argument and refers to a window containing a frameset
<LI><A HREF="ref_s-s.htm#self_property" self_property">self</A> is a synonym for the <I>windowName</I> argument and refers to the current window
<LI><A HREF="ref_s-s.htm#status_property" status_property">status</A> specifies a priority or transient message in the window's status bar
<LI><A HREF="ref_t-z.htm#top_property" top_property">top</A> is a synonym for the <I>windowName</I> argument and refers to the top-most Navigator window
<LI><A HREF="ref_t-z.htm#window_property" window_property">window</A> is a synonym for the <I>windowName</I> argument and refers to the current window

<P>The following objects are also properties of the window object:
<LI><A HREF="ref_d-e.htm#document_object" document_object">document</A>
<LI><A HREF="ref_f-g.htm#frame_object" frame_object">frame</A>
<LI><A HREF="ref_h-l.htm#location_object" location_object">location</A>


<H3>Methods</H3>
<LI><A HREF="ref_a-c.htm#alert_method" alert_method">alert</A>
<LI><A HREF="ref_a-c.htm#close_window_method" close_window_method">close</A>
<LI><A HREF="ref_a-c.htm#confirm_method" confirm_method">confirm</A>
<LI><A HREF="ref_m-q.htm#open_window_method" open_window_method">open</A>
<LI><A HREF="ref_m-q.htm#prompt_method" prompt_method">prompt</A>
<LI><A HREF="ref_s-s.htm#setTimeout_method" setTimeout_method">setTimeout</A>
<LI><A HREF="ref_a-c.htm#clearTimeout_method" clearTimeout_method">clearTimeout</A>


<H3>Event handlers</H3>
<LI><A HREF="ref_m-q.htm#onLoad_event" onLoad_event">onLoad</A>
<LI><A HREF="ref_m-q.htm#onUnload_event" onUnload_event">onUnload</A>


<H3>例子</H3>
<P>In the following example, the document in the top window opens a second window, <I>window2,</I> and defines pushbuttons that open a message window, write to the message window, close the message window, and close <I>window2.</I> The onLoad and onUnload event handlers of the document loaded into <I>window2</I> display alerts when the window opens and closes.

<P>WIN1.htm, which defines the frames for the first window, contains the following code:
<XMP>
<htm>
<HEAD>
<TITLE>Window object example: Window 1</TITLE>
</HEAD>
<BODY BGCOLOR="antiquewhite">
<SCRIPT>
window2=open("win2.htm","secondWindow","scrollbars=yes,width=250, height=400")
document.writeln("<B>The first window has no name: " + window.name + "</B>")
document.writeln("<BR><B>The second window is named: " + window2.name + "</B>")
</SCRIPT>
<FORM NAME="form1">
<P><INPUT TYPE="button" VALUE="Open a message window"
   onClick="window3=window.open('','messageWindow','scrollbars=yes,width=175, height=300')">
<P><INPUT TYPE="button" VALUE="Write to the message window"
   onClick="window3.document.writeln('Hey there');window3.document.close()">
<P><INPUT TYPE="button" VALUE="Close the message window"
   onClick="window3.close()">
<P><INPUT TYPE="button" VALUE="Close window2"
   onClick="window2.close()">
</FORM>
</BODY>
</htm>
</XMP>

<P>WIN2.htm, which defines the content for <I>window2</I>, contains the following code:
<XMP>
<htm>
<HEAD>
<TITLE>Window object example: Window 2</TITLE>
</HEAD>
<BODY BGCOLOR="oldlace"
   onLoad="alert('Message from ' + window.name + ': Hello, World.')"
   onUnload="alert('Message from ' + window.name + ': I\'m closing')">
<B>Some numbers</B>
<LI>one
<LI>two
<LI>three
<LI>four
<LI>five
<LI>six
<LI>seven
<LI>eight
<LI>nine
</BODY>
</htm>
</XMP>

<P>相关 the example for the <A HREF="ref_f-g.htm#frame_object" frame_object">frame</A> object.


<H3>相关</H3>
<LI><A HREF="ref_d-e.htm#document_object" document_object">document</A> and <A HREF="ref_f-g.htm#frame_object" frame_object">frame</A> objects

<!------------------------------------------------------------------------------------------------->
<HR>
<A NAME="window_property"><H2>window property</H2></A>
<P>
The window property is a synonym for the current window or frame.

<H3>语法</H3>
<PRE>
1. window.<I>propertyName</I>
2. window.<I>methodName</I>
</PRE>
<P><I>propertyName</I> is the defaultStatus, status, length, or name property when the calling window refers to a window object.
<BR><I>propertyName</I> is the length or name property when the calling window refers to a frame object.
<BR><I>methodName</I> is any method associated with the window object.

<H3>Property of</H3>
<P><A HREF="ref_f-g.htm#frame_object" frame_object">frame</A>, <A HREF="ref_t-z.htm#window_object" window_object">window</A>

<H3>描述</H3>
<P>The window property refers to the current window or frame.

<P> Although you can use the window property as a synonym for the current frame, your code is more readable if you use the self property. For example, <TT>window.name</TT> and <TT>self.name</TT> both specify the name of the current frame, but <TT>self.name</TT> is easier to understand.

<P>Use the window property to disambiguate a property of the window object from a form or form element of the same name. You can also use the window property to make your code more readable.

<P>The window property is read-only. The value of the window property is
<PRE>     &ltobject <I>nameAttribute</I>&gt</PRE>
where <I>nameAttribute</I> is the NAME attribute if window refers to a frame, or an internal reference if window refers to a window.

<H3>例子</H3>
<P>In the following example, <TT>window.status</TT> is used to set the status property of the current window. This usage disambiguates the status property of the current window from a form called "status" within the current window.
<XMP><A HREF=""
   onClick="this.href=pickRandomURL()"
   onMouseOver="window.status='Pick a random URL' ; return true">
Go!</A></XMP>


<H3>相关</H3>
<LI><A HREF="ref_s-s.htm#self_property" self_property">self</A> property
<!------------------------------------------------------------------------------------------------->
<HR>
<A NAME="write_method"><H2>write method</H2></A>
<P>
Writes one or more htm expressions to a document in the specified window.

<H3>语法</H3>
<PRE>document.write(<I>expression1</I> [,<I>expression2</I>], ...[,<I>expressionN</I>])</PRE>
<I>expression1</I> through <I>expressionN</I> are any JavaScript expressions or the properties of existing objects.

<H3>用法</H3>
<P><A HREF="ref_d-e.htm#document_object" document_object">document</A>

<H3>描述</H3>
<P>The write method displays any number of expressions in a document window. You can specify any JavaScript expression with the write method, including numerics, strings, or logicals.

<P>The write method is the same as the writeln method, except the write method does not append a newline character to the end of the output.

<P>Use the write method within any &ltSCRIPT&gt tag or within an event handler. Event handlers execute after the original document closes, so the write method will implicitly open a new document of <I>mimeType</I> <TT>text/htm</TT> if you do not explicitly issue a document.open() method in the event handler.

<H3>例子</H3>
In the following example, the write method takes several arguments, including strings, a numeric, and a variable:
<PRE>
var mystery = "world"
// Displays Hello world testing 123
msgWindow.document.write("Hello ", mystery, " testing ", 123)
</PRE>

In the following example, the write method takes two arguments. The first argument is an assignment expression, and the second argument is a string literal.
<PRE>
//Displays Hello world...
msgWindow.document.write(mystr = "Hello "+ "world...")
</PRE>

In the following example, the write method takes a single argument that is a conditional expression. If the value of the variable <I>age</I> is less than 18, the method displays "Minor". If the value of <I>age</I> is greater than or equal to 18, the method displays "Adult".
<PRE>
msgWindow.document.write(status = (age >= 18) ? "Adult" : "Minor")
</PRE>

<H3>相关</H3>
<LI><A HREF="ref_a-c.htm#close_document_method" close_document_method">close</A>, <A HREF="ref_a-c.htm#clear_method" clear_method">clear</A>, <A HREF="ref_m-q.htm#open_document_method" open_document_method">open</A>, <A HREF="ref_t-z.htm#writeln_method" writeln_method">writeln</A> methods
<!------------------------------------------------------------------------------------------------>
<HR>
<A NAME="writeln_method"><H2>writeln method</H2></A>
<P>
Writes one or more htm expressions to a document in the specified window and follows them with a newline character.

<H3>语法</H3>
<PRE>document.writeln(<I>expression1</I> [,<I>expression2</I>], ...[,<I>expressionN</I>])</PRE>
<I>expression1</I> through <I>expressionN</I> are any JavaScript expressions or the properties of existing objects.

<H3>用法</H3>
<P><A HREF="ref_d-e.htm#document_object" document_object">document</A>

<H3>描述</H3>
<P>The writeln method displays any number of expressions in a document window. You can specify any JavaScript expression, including numerics, strings, or logicals.

<P>The writeln method is the same as the write method, except the writeln method appends a newline character to the end of the output. htm ignores the newline character, except within certain tags such as &ltPRE&gt.

<P>Use the writeln method within any &ltSCRIPT&gt tag or within an event handler. Event handlers execute after the original document closes, so the writeln method will implicitly open a new document of <I>mimeType</I> <TT>text/htm</TT> if you do not explicitly issue a document.open() method in the event handler.

<H3>例子</H3>
<P>All the 例子 used for the <A HREF="ref_t-z.htm#write_method" write_method">write</A> method are also valid with the writeln method.

<H3>相关</H3>
<LI><A HREF="ref_a-c.htm#close_document_method" close_document_method">close</A>, <A HREF="ref_a-c.htm#clear_method" clear_method">clear</A>, <A HREF="ref_m-q.htm#open_document_method" open_document_method">open</A>, <A HREF="ref_t-z.htm#write_method" write_method">write</A> methods
<!------------------------------------------------------------------------------------------------->
<HR>

<SCRIPT>
document.write("<FONT SIZE=-2>Last modified " + document.lastModified)
</SCRIPT>
<P>
</BODY>
<htm>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -