📄 ref_a-c.htm
字号:
<LI><A HREF="ref_d-e.htm#encoding_property" encoding_property">encoding</A>, <A HREF="ref_m-q.htm#method_property" method_property">method</A>, <A HREF="ref_t-z.htm#target_property" target_property">target</A> properties
<!------------------------------------------------------------------------------------------------->
<HR>
<A NAME="alert_method"><H2>alert method</H2></A>
<P>
Displays an Alert dialog box with a message and an OK button.
<H3>语法</H3>
<PRE>alert("<I>message</I>")</PRE>
<P><I>message</I> is any string or a property of an existing object.
<H3>用法</H3>
<P><A HREF="ref_t-z.htm#window_object" window_object">window</A>
<H3>描述</H3>
<P>Use the alert method to display a message that does not require a user decision. The <I>message</I> argument specifies a message that the dialog box contains.
<P>Although alert is a 用法 the window object, you do not need to specify a <I>windowReference</I> when you call it. For example, <TT><I>windowReference</I>.alert()</TT> is unnecessary.
<H3>例子</H3>
<P>In the following example, the <I>testValue()</I> function checks the name entered by a user in the text object of a form to make sure that it is no more than eight characters in length. This example uses the alert method to prompt the user to enter a valid value.
<PRE>
function testValue(textElement) {
if (textElement.length > 8) {
alert("Please enter a name that is 8 characters or less")
}
}</PRE>
You can call the <I>testValue()</I> function in the onBlur event handler of a form's text object, as shown in the following example:
<PRE>Name: <INPUT TYPE="text" NAME="userName"
onBlur="testValue(userName.value)"></PRE>
<H3>See also</H3>
<LI><A HREF="ref_a-c.htm#confirm_method" confirm_method">confirm</A>, <A HREF="ref_m-q.htm#prompt_method" prompt_method">prompt</A> methods
<!------------------------------------------------------------------------------------------------>
<HR>
<A NAME="alinkColor_property"><H2>alinkColor property</H2></A>
<P>
A string specifying the color of an active link (after mouse-button down, but before mouse-button up).
<H3>语法</H3>
<PRE>document.alinkColor</PRE>
<H3>Property of</H3>
<P><A HREF="ref_d-e.htm#document_object" document_object">document</A>
<H3>描述</H3>
<P>
The alinkColor 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 ALINK attribute of the <BODY> tag. 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 active links to aqua using a string literal:
<PRE>
document.alinkColor="aqua"
</PRE>
<P>The following example sets the color of active links to aqua using a hexadecimal triplet:
<PRE>
document.alinkColor="00FFFF"
</PRE>
<H3>See also</H3>
<LI><A HREF="ref_a-c.htm#bgColor_property" bgColor_property">bgColor</A>, <A HREF="ref_f-g.htm#fgColor_property" fgColor_property">fgColor</A>, <A HREF="ref_h-l.htm#linkColor_property" linkColor_property">linkColor</A>, and <A HREF="ref_t-z.htm#vlinkColor_property" vlinkColor_property">vlinkColor</A> properties
<!------------------------------------------------------------------------------------------------->
<HR>
<A NAME="anchor_method"><H2>anchor method</H2></A>
<P>
Creates an htm anchor that is used as a hypertext target.
<H3>语法</H3>
<PRE><I>text</I>.anchor(<I>nameAttribute</I>)</PRE>
<P><I>text</I> is any string or a property of an existing object.
<BR><I>nameAttribute</I> is any string or a property of an existing object.
<H3>用法</H3>
<P><A HREF="ref_s-s.htm#string_object" string_object">string</A>
<H3>描述</H3>
<P>Use the anchor method with the write or writeln methods to programatically create and display an anchor in a document. Create the anchor with the anchor method, then call write or writeln to display the anchor in a document.
<P>In the 语法, the <I>text</I> string represents the literal text that you want the user to see. The <I>nameAttribute</I> string represents the NAME attribute of the <A> tag.
<P>Anchors created with the anchor method become elements in the anchors array. See the <A HREF="ref_a-c.htm#anchor_object" anchor_object">anchor</A> object for information about the anchors array.
<H3>例子</H3>
<P>The following example opens the <I>msgWindow</I> window and creates an anchor for the Table of Contents:
<XMP>
var myString="Table of Contents"
msgWindow=window.open("","displayWindow")
msgWindow.document.writeln(myString.anchor("contents_anchor"))
msgWindow.document.close()
</XMP>
<P>The previous example produces the same output as the following htm:
<XMP>
<A NAME="contents_anchor">Table of Contents</A>
</XMP>
<H3>See also</H3>
<LI><A HREF="ref_h-l.htm#link_method" link_method">link</A> method
<!------------------------------------------------------------------------------------------------>
<HR>
<A NAME="anchor_object"><H2>anchor object (<I>anchors</I> array)</H2></A>
<P>A piece of text that can be the target of a hypertext link.
<H3>语法</H3>
<P>To define an anchor, use standard htm 语法:
<PRE>
<A [HREF=<I>locationOrURL</I>]
NAME="<I>anchorName</I>"
[TARGET="<I>windowName</I>"]>
<I>anchorText</I>
</A>
</PRE>
<I>HREF=locationOrURL</I> identifies a destination anchor or URL. If this attribute is present, the anchor object is also a link object. See <A HREF="ref_h-l.htm#link_object" link_object">link</A> for details.
<BR><I>NAME="anchorName"</I> specifies a tag that becomes an available hypertext target within the current document.
<BR><I>TARGET="windowName"</I> specifies the window that the link is loaded into. This attribute is meaningful only if <I>HREF=locationOrURL</I> is present. See <A HREF="ref_h-l.htm#link_object" link_object">link</A> for details.
<BR><I>anchorText</I> specifies the text to display at the anchor.
<P>You can also define an anchor using the <A HREF="ref_a-c.htm#anchor_method" anchor_method">anchor</A> method.
<H3>Property of</H3>
<LI><A HREF="ref_d-e.htm#document_object" document_object">document</A>
<H3>描述</H3>
<P>If an anchor object is also a link object, the object has entries in both the <I>anchors</I> and <I>links</I> arrays.
<H4>The <I>anchors</I> array</H4>
<P>You can reference the anchor objects in your code by using the <I>anchors</I> array. This array contains an entry for each <A> tag containing a NAME attribute in a document in source order. For example, if a document contains three named anchors, these anchors are reflected as <TT>document.anchors[0]</TT>, <TT>document.anchors[1]</TT>, and <TT>document.anchors[2]</TT>.
<P>To use the <I>anchors</I> array:
<PRE>
1. document.anchors[<I>index</I>]
2. document.anchors.length
</PRE>
<P><I>index</I> is an integer representing an anchor in a document.
<P>To obtain the number of anchors in a document, use the length property: <TT>document.anchors.length</TT>.
<P>Even though the <I>anchors</I> array represents named anchors, the value of anchors[<I>index</I>] is always null. But if a document names anchors in a systematic way using natural numbers, you can use the <I>anchors</I> array and its length property to validate an anchor name before using it in operations such as setting <TT>location.hash</TT>. See the example below.
<P>Elements in the <I>anchors</I> array are read-only. For example, the statement <TT>document.anchors[0]="anchor1"</TT> has no effect.
<H3>Properties</H3>
<P>The anchors object has no properties. The <I>anchors</I> array has the following properties:
<LI><A HREF="ref_h-l.htm#length_property" length_property">length</A> reflects the number of named anchors in a document
<H3>Methods</H3>
<LI>None.
<H3>Event handlers</H3>
<LI>None.
<H3>例子</H3>
<P><B>Example 1: an anchor.</B> The following example defines an anchor for the text "Welcome to JavaScript".
<XMP>
<A NAME="javascript_intro"><H2>Welcome to JavaScript</H2></A>
</XMP>
<P>If the preceding anchor is in a file called intro.htm, a link in another file could define a jump to the anchor as follows:
<XMP>
<A HREF="tppmsgs/msgs0.htm#8" tppabs="http://www.nease.net/~jim/intro.htm#javascript_intro">Introduction</A>
</XMP>
<P><B>Example 2: anchors array.</B> The following example opens two windows. The first window contains a series of buttons that set <TT>location.hash</TT> in the second window to a specific anchor. The second window defines four anchors named "0", "1", "2", and "3". (The anchor names in the document are therefore 0, 1, 2, ... (document.anchors.length-1)). When a button is pressed in the first window, the onClick event handler verifies that the anchor exists before setting <TT><I>window2</I>.location.hash</TT> to the specified anchor name.
<P>LINK1.htm, which defines the first window and its buttons, contains the following code:
<XMP>
<htm>
<HEAD>
<TITLE>Links and Anchors: Window 1</TITLE>
</HEAD>
<BODY>
<SCRIPT>
window2=open("link2.htm","secondLinkWindow","scrollbars=yes,width=250, height=400")
function linkToWindow(num) {
if (window2.document.anchors.length > num)
window2.location.hash=num
else
alert("Anchor does not exist!")
}
</SCRIPT>
<B>Links and Anchors</B>
<FORM>
<P>Click a button to display that anchor in window #2
<P><INPUT TYPE="button" VALUE="0" NAME="link0_button"
onClick="linkToWindow(this.value)">
<INPUT TYPE="button" VALUE="1" NAME="link0_button"
onClick="linkToWindow(this.value)">
<INPUT TYPE="button" VALUE="2" NAME="link0_button"
onClick="linkToWindow(this.value)">
<INPUT TYPE="button" VALUE="3" NAME="link0_button"
onClick="linkToWindow(this.value)">
<INPUT TYPE="button" VALUE="4" NAME="link0_button"
onClick="linkToWindow(this.value)">
</FORM>
</BODY>
</htm>
</XMP>
<P>LINK2.htm, which contains the anchors, contains the following code:
<XMP>
<htm>
<HEAD>
<TITLE>Links and Anchors: Window 2</TITLE>
</HEAD>
<BODY>
<A NAME="0"><B>Some numbers</B> (Anchor 0)</A>
<LI>one
<LI>two
<LI>three
<LI>four
<LI>five
<LI>six
<LI>seven
<LI>eight
<LI>nine
<P><A NAME="1"><B>Some colors</B> (Anchor 1)</A>
<LI>red
<LI>orange
<LI>yellow
<LI>green
<LI>blue
<LI>purple
<LI>brown
<LI>black
<P><A NAME="2"><B>Some music types</B> (Anchor 2)</A>
<LI>R&B
<LI>Jazz
<LI>Soul
<LI>Reggae
<LI>Rock
<LI>Country
<LI>Classical
<LI>Opera
<P><A NAME="3"><B>Some countries</B> (Anchor 3)</A>
<LI>Afghanistan
<LI>Brazil
<LI>Canada
<LI>Finland
<LI>India
<LI>Italy
<LI>Japan
<LI>Kenya
<LI>Mexico
<LI>Nigeria
</BODY>
</htm>
</XMP>
<H3>See also</H3>
<LI><A HREF="ref_h-l.htm#link_object" link_object">link</A> object
<LI><A HREF="ref_a-c.htm#anchor_method" anchor_method">anchor</A> method
<!------------------------------------------------------------------------------------------------->
<HR>
<A NAME="anchors_property"><H2>anchors property</H2></A>
<P>An array of objects corresponding to named anchors in source order. See <A HREF="ref_a-c.htm#anchor_object" anchor_object">anchor</A> object.
<!------------------------------------------------------------------------------------------------->
<HR>
<A NAME="appCodeName_property"><H2>appCodeName property</H2></A>
<P>A string specifying the code name of the browser.
<H3>语法</H3>
<PRE>navigator.appCodeName</PRE>
<H3>Property of</H3>
<P><A HREF="ref_m-q.htm#navigator_object" navigator_object">navigator</A>
<H3>描述</H3>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -