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

📄 ref_h-l.htm

📁 javascript函数大全HTML javascript函数大全HTML
💻 HTM
📖 第 1 页 / 共 4 页
字号:
12. <I>windowReference</I>.frames.length
13. links.length
14. <I>selectName</I>.options.length
</PRE>

<P><I>formName</I> is either the name of a form or an element in the forms array.
<BR><I>frameReference</I> is either the value of the NAME attribute of a frame or an element in the <I>frames</I> array.
<BR><I>radioName</I> is either the value of the NAME attribute of a radio object or an element in the <I>elements</I> array.
<BR><I>selectName</I> is either the value of the NAME attribute of a select object or an element in the <I>elements</I> array.
<BR><I>stringName</I> is any string or a property of an existing object.
<BR><I>windowReference</I> is a valid way of referring to a window, as described in the <A HREF="ref_t-z.htm#window_object" window_object">window</A> object.

<H3>Property of</H3>
<LI><A HREF="ref_f-g.htm#frame_object" frame_object">frame</A>, <A HREF="ref_h-l.htm#history_object" history_object">history</A>, <A HREF="ref_r-r.htm#radio_object" radio_object">radio</A>, <A HREF="ref_s-s.htm#select_object" select_object">select</A>, <A HREF="ref_s-s.htm#string_object" string_object">string</A>, <A HREF="ref_t-z.htm#window_object" window_object">window</A> objects
<LI><A HREF="ref_a-c.htm#anchor_object" anchor_object">anchors</A>, <A HREF="ref_d-e.htm#elements_object" elements_object">elements</A>, <A HREF="ref_f-g.htm#form_object" form_object">forms</A>, <A HREF="ref_f-g.htm#frame_object" frame_object">frames</A>, <A HREF="ref_h-l.htm#link_object" link_object">links</A>, <A HREF="ref_s-s.htm#select_object" select_object">options</A> arrays

<H3>描述</H3>
<P>The length property is an integer that specifies one of the following:
<LI>The number of elements on a form (form 1 of the 语法).
<LI>The number of frames within a frame (form 2 of the 语法). A frame that does not load a document containing a &ltFRAMESET&gt tag always has a length of 0.
<LI>The number of entries in a history object (form 3 of the 语法).
<LI>The number of radio buttons in a radio object (form 4 of the 语法).
<LI>The number of options in a select object (form 5 of the 语法).
<LI>The length of a string object (form 6 of the 语法).
<LI>The number of frames in a parent window (form 7 of the 语法).
<LI>The number of entries in one of the array properties (all other 语法 forms).

<P>length is always a read-only property.

<P>For a null string, length is zero. For a select object, the values returned by form 5 and form 14 of the 语法 are the same. For a window containing frames, the values returned by form 7 and form 12 of the 语法 are the same. For a form object, the values returned by form 1 and form 9 of the 语法 are the same. For a frame containing frames, the values returned by form 2 and form 11 of the 语法 are the same. 

<H3>例子</H3>
<P>In the following example, the <I>getChoice()</I> function uses the length property to iterate over every element in the <I>musicType</I> array. <I>musicType</I> is a select element on the <I>musicForm</I> form.
<PRE>
function getChoice() {
   for (var i = 0; i < document.musicForm.musicType.length; i++) {
      if (document.musicForm.musicType.options[i].selected == true) {
         return document.musicForm.musicType.options[i].text
      }
   }
}
</PRE>

<P>The following example displays 8 in an alert dialog box:
<PRE>var x="Netscape"
alert("The string length is " + x.length)
</PRE>
<!------------------------------------------------------------------------------------------------->
<HR>
<A NAME="link_method"><H2>link method</H2></A>
<P>
Creates an htm hypertext link that jumps to another URL.

<H3>语法</H3>
<PRE><I>linkText</I>.link(<I>hrefAttribute</I>)</PRE>
<P><I>linkText</I> is any string or a property of an existing object.
<BR><I>hrefAttribute</I> is any string or a property of an existing object.

<H3>Method of</H3>
<P><A HREF="ref_s-s.htm#string_object" string_object">string</A>

<H3>描述</H3>
<P>Use the link method with the write or writeln methods to programatically create and display a hypertext link in a document. Create the link with the link method, then call write or writeln to display the link in a document.

<P>In the 语法, the <I>linkText</I> string represents the literal text that you want the user to see. The <I>hrefAttribute</I> string represents the HREF attribute of the &ltA&gt tag, and it should be a valid URL. Each section of a URL contains different information. See the <A HREF="ref_h-l.htm#location_object" location_object">location</A> object for a 描述 of the URL components.

<P>Links created with the link method become elements in the links array. See the <A HREF="ref_h-l.htm#link_object" link_object">link</A> object for information about the links array.

<H3>例子</H3>
<P>The following example displays the word "Netscape" as a hypertext link that returns the user to the Netscape home page:
<PRE>
var hotText="Netscape"
var URL="http://www.netscape.com"

document.open()
document.write("Click to return to " + hotText.link(URL))
document.close()
</PRE>
<P>The previous example produces the same output as the following htm:
<P><TT>Click to return to &ltA HREF="http://www.netscape.com"&gtNetscape&lt/A&gt</TT>

<H3>相关</H3>
<LI><A HREF="ref_a-c.htm#anchor_method" anchor_method">anchor</A> method
<!------------------------------------------------------------------------------------------------>
<HR>
<A NAME="link_object"><H2>link object (<I>links</I> array)</H2></A>
<P>A piece of text or an image identified as a hypertext link. When the user clicks the link text, the link hypertext reference is loaded into its target window.


<H3>语法</H3>
<P>To define a link, use standard htm 语法 with the addition of the onClick and onMouseOver event handlers:
<PRE>
&LTA HREF=<I>locationOrURL</I>
   [NAME="<I>anchorName</I>"]
   [TARGET="<I>windowName</I>"]
   [onClick="<I>handlerText</I>"]
   [onMouseOver="<I>handlerText</I>"]&GT
   <I>linkText</I>
&LT/A&GT
</PRE>
<I>HREF=locationOrURL</I> identifies a destination anchor or URL. See the <A HREF="ref_h-l.htm#location_object" location_object">location</A> object for a 描述 of the URL components.
<BR><I>NAME="anchorName"</I> specifies a tag that becomes an available hypertext target within the current document. If this attribute is present, the link object is also an anchor object. See <A HREF="ref_a-c.htm#anchor_object" anchor_object">anchor</A> for details.
<BR><I>TARGET="windowName"</I> specifies the window that the link is loaded into. <I>windowName</I> can be an existing window; it can be a frame name specified in a &LTFRAMESET&GT 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>).
<BR><I>linkText</I> is rendered as a hypertext link to the URL.

<P>You can also define a link using the <A HREF="ref_h-l.htm#link_method" link_method">link</A> method.

<P>To use a link object's properties:
<PRE>
document.links[<I>index</I>].<I>propertyName</I>
</PRE>
<I>index</I> is an integer representing a link object.
<BR><I>propertyName</I> is one of the properties listed below.


<H3>Property of</H3>
<LI><A HREF="ref_d-e.htm#document_object" document_object">document</A>


<H3>描述</H3>
<P>Each link object is a location object and has the same properties as a location object.

<P>If a link object is also an anchor object, the object has entries in both the <I>anchors</I> and <I>links</I> arrays.

<P>When a user clicks a link object and navigates to the destination document (specified by <I>HREF=locationOrURL</I>), the destination document's referrer property contains the URL of the source document. Evaluate the referrer property from the destination document.


<H4>The <I>links</I> array</H4>
<P>You can reference the link objects in your code by using the <I>links</I> array. This array contains an entry for each link object (&LTA HREF=""&GT tag) in a document in source order. For example, if a document contains three link objects, these links are reflected as <TT>document.links[0]</TT>, <TT>document.links[1]</TT>, and <TT>document.links[2]</TT>.

<P>To use the <I>links</I> array:
<PRE>
1. document.links[<I>index</I>]
2. document.links.length
</PRE>
<P><I>index</I> is an integer representing a link in a document.

<P>To obtain the number of links in a document, use the length property: <TT>document.links.length</TT>.

<P>Elements in the <I>links</I> array are read-only. For example, the statement <TT>document.links[0]="link1"</TT> has no effect.


<H3>Properties</H3>
<P>The link object has the following properties:
<LI><A HREF="ref_h-l.htm#hash_property" hash_property">hash</A> specifies an anchor name in the URL
<LI><A HREF="ref_h-l.htm#host_property" host_property">host</A> specifies the hostname:port portion of the URL
<LI><A HREF="ref_h-l.htm#hostname_property" hostname_property">hostname</A> specifies the host and domain name, or IP address, of a network host
<LI><A HREF="ref_h-l.htm#href_property" href_property">href</A> specifies the entire URL
<LI><A HREF="ref_m-q.htm#pathname_property" pathname_property">pathname</A> specifies the url-path portion of the URL
<LI><A HREF="ref_m-q.htm#port_property" port_property">port</A> specifies the communications port that the server uses for communications
<LI><A HREF="ref_m-q.htm#protocol_property" protocol_property">protocol</A> specifies the beginning of the URL, including the colon
<LI><A HREF="ref_s-s.htm#search_property" search_property">search</A> specifies a query
<LI><A HREF="ref_t-z.htm#target_property" target_property">target</A> reflects the TARGET attribute

<P>The <I>links</I> array has the following properties:
<LI><A HREF="ref_h-l.htm#length_property" length_property">length</A> reflects the number of links in a document


<H3>Methods</H3>
<LI>None.


<H3>Event handlers</H3>
<LI><A HREF="ref_m-q.htm#onClick_event" onClick_event">onClick</A>
<LI><A HREF="ref_m-q.htm#onMouseOver_event" onMouseOver_event">onMouseOver</A>


<H3>例子</H3>
<P><B>Example 1.</B> The following example creates a hypertext link to an anchor named <I>javascript_intro</I>.
<XMP>
<A HREF="#javascript_intro">Introduction to JavaScript</A>
</XMP>

<P><B>Example 2.</B> The following example creates a hypertext link to an anchor named <I>numbers</I> in the file DOC3.htm in the window <I>window2</I>. If <I>window2</I> does not exist, it is created.
<XMP>
<LI><A HREF="tppmsgs/msgs0.htm#16" tppabs="http://www.nease.net/~jim/doc3.htm#numbers" TARGET="window2">Numbers</A>
</XMP>

<P><B>Example 3.</B> The following example takes the user back <I>x</I> entries in the history list:
<XMP>
<A HREF="javascript:history.go(-1 * x)">Click here</A>
</XMP>

<P><B>Example 4.</B> The following example creates a hypertext link to a URL. A set of radio buttons lets the user choose between three URLs. The link's onClick event handler sets the URL (the link's href property) based on the selected radio button. The link also has an onMouseOver event handler that changes the window's status property. As the example shows, you must return true to set the window.status property in the onMouseOver event handler.
<XMP>
<SCRIPT>
var destHREF="'http://www.netscape.com/"
</SCRIPT>
<FORM NAME="form1">
<B>Choose a destination from the following list, then click "Click me" below.</B>
<BR><INPUT TYPE="radio" NAME="destination" VALUE="netscape"
   onClick="destHREF='http://www.netscape.com/'"> Netscape home page
<BR><INPUT TYPE="radio" NAME="destination" VALUE="sun"
   onClick="destHREF='http://www.sun.com/'"> Sun home page
<BR><INPUT TYPE="radio" NAME="destination" VALUE="rfc1867"
   onClick="destHREF='http://www.ics.uci.edu/pub/ietf/htm/rfc1867.txt'"> RFC 1867
<P><A HREF=""
   onMouseOver="window.status='Click this if you dare!'; return true"
   onClick="this.href=destHREF">
   <B>Click me</B></A>
</FORM>
</XMP>

<P><B>Example 5: <I>links</I> array.</B> The following example opens the Netscape home page in the <I>newWindow</I> window. The <I>linkGetter()</I> function uses the links array to display the value of each of its links.
<XMP>
   newWindow=window.open("http://www.netscape.com")

function linkGetter() {
   msgWindow=window.open("")
   for (var i = 0; i < newWindow.document.links.length; i++) {
      msgWindow.document.write(newWindow.document.links[i] + "<BR>")
   }
}
</XMP>


<H3>相关</H3>
<LI><A HREF="ref_a-c.htm#anchor_object" anchor_object">anchor</A> object
<LI><A HREF="ref_h-l.htm#link_method" link_method">link</A> method


<!------------------------------------------------------------------------------------------------->
<HR>
<A NAME="linkColor_property"><H2>linkColor property</H2></A>
<P>
A string specifying the color of the document hyperlinks.

<H3>语法</H3>
<PRE>document.linkColor</PRE>

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

<H3>描述</H3>
<P>The linkColor property is expressed as a hexadecimal RGB triplet or as one of the string literals listed in <A HREF="tppmsgs/msgs0.htm#11" tppabs="http://www.nease.net/~jim/colors.htm">Color Values</A>. This property is the JavaScript reflection of the LINK attribute of the &ltBODY&gt tag. The default value of this property is set by the user on the Colors tab of the Preferences dialog box, which is displayed by choosing General Preferences from the Options menu. You cannot set this property after the htm source has been through layout.

<P>If you express the color as a hexadecimal RGB triplet, you must use the format rrggbb. For example, the hexadecimal RGB values for salmon are red=FA, green=80, and blue=72, so the RGB triplet for salmon is "FA8072".

<H3>例子</H3>
<P>The following example sets the color of document links to aqua using a string literal:
<PRE>
document.linkColor="aqua"
</PRE>
<P>The following example sets the color of document links to aqua using a hexadecimal triplet:
<PRE>
document.linkColor="00FFFF"
</PRE>

<H3>相关</H3>
<LI><A HREF="ref_a-c.htm#alinkColor_property" alinkColor_property">alinkColor</A>, <A HREF="ref_a-c.htm#bgColor_property" bgColor_property">bgColor</A>, <A HREF="ref_f-g.htm#fgColor_property" fgColor_property">fgColor</A>, and <A HREF="ref_t-z.htm#vlinkColor_property" vlinkColor_property">vlinkColor</A> properties
<!------------------------------------------------------------------------------------------------->
<HR>
<A NAME="links_property"><H2>links property</H2></A>
<P>An array of objects corresponding to link objects in source order. See <A HREF="ref_h-l.htm#link_object" link_object">link</A> object.

<!------------------------------------------------------------------------------------------------->
<HR>
<A NAME="LN2_property"><H2>LN2 property</H2></A>
<P>
The natural logarithm of two, approximately 0.693.

<H3>语法</H3>
<PRE>Math.LN2</PRE>

<H3>Property of</H3>

⌨️ 快捷键说明

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