?? ref_d-e.htm
字號:
<LI><A HREF="ref_h-l.htm#history_object" history_object">history</A>
<LI><A HREF="ref_h-l.htm#link_object" link_object">link</A>
<H3>Methods</H3>
<LI><A HREF="ref_a-c.htm#clear_method" clear_method">clear</A>
<LI><A HREF="ref_a-c.htm#close_document_method" close_document_method">close</A>
<LI><A HREF="ref_m-q.htm#open_document_method" open_document_method">open</A>
<LI><A HREF="ref_t-z.htm#write_method" write_method">write</A>
<LI><A HREF="ref_t-z.htm#writeln_method" writeln_method">writeln</A>
<H3>Event handlers</H3>
<LI>None. The onLoad and onUnload event handlers are specified in the <BODY> tag but are actually event handlers for the window object.
<H3>例子</H3>
<P>The following example creates two frames, each with one document. The document in the first frame contains links to anchors in the document of the second frame. Each document defines its colors.
<P>DOC0.htm, which defines the frames, contains the following code:
<XMP>
<htm>
<HEAD>
<TITLE>Document object example</TITLE>
</HEAD>
<FRAMESET COLS="30%,70%">
<FRAME SRC="tppmsgs/msgs0.htm#9" tppabs="http://www.nease.net/~jim/doc1.htm" NAME="frame1">
<FRAME SRC="tppmsgs/msgs0.htm#10" tppabs="http://www.nease.net/~jim/doc2.htm" NAME="frame2">
</FRAMESET>
</htm>
</XMP>
<P>DOC1.htm, which defines the content for the first frame, contains the following code:
<XMP>
<htm>
<SCRIPT>
</SCRIPT>
<BODY
BGCOLOR="antiquewhite"
TEXT="darkviolet"
LINK="fuchsia"
ALINK="forestgreen"
VLINK="navy">
<P><B>Some links</B>
<LI><A HREF="tppmsgs/msgs0.htm#10" tppabs="http://www.nease.net/~jim/doc2.htm#numbers" TARGET="frame2">Numbers</A>
<LI><A HREF="tppmsgs/msgs0.htm#10" tppabs="http://www.nease.net/~jim/doc2.htm#colors" TARGET="frame2">Colors</A>
<LI><A HREF="tppmsgs/msgs0.htm#10" tppabs="http://www.nease.net/~jim/doc2.htm#musicTypes" TARGET="frame2">Music types</A>
<LI><A HREF="tppmsgs/msgs0.htm#10" tppabs="http://www.nease.net/~jim/doc2.htm#countries" TARGET="frame2">Countries</A>
</BODY>
</htm>
</XMP>
<P>DOC2.htm, which defines the content for the second frame, contains the following code:
<XMP>
<htm>
<SCRIPT>
</SCRIPT>
<BODY
BGCOLOR="oldlace" onLoad="alert('Hello, World.')"
TEXT="navy">
<P><A NAME="numbers"><B>Some numbers</B></A>
<LI>one
<LI>two
<LI>three
<LI>four
<LI>five
<LI>six
<LI>seven
<LI>eight
<LI>nine
<P><A NAME="colors"><B>Some colors</B></A>
<LI>red
<LI>orange
<LI>yellow
<LI>green
<LI>blue
<LI>purple
<LI>brown
<LI>black
<P><A NAME="musicTypes"><B>Some music types</B></A>
<LI>R&B
<LI>Jazz
<LI>Soul
<LI>Reggae
<LI>Rock
<LI>Country
<LI>Classical
<LI>Opera
<P><A NAME="countries"><B>Some countries</B></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_f-g.htm#frame_object" frame_object">frame</A> and <A HREF="ref_t-z.htm#window_object" window_object">window</A> objects
<!------------------------------------------------------------------------------------------------->
<HR>
<A NAME="E_property"><H2>E property</H2></A>
<P>
Euler's constant and the base of natural logarithms, approximately 2.718.
<H3>語法</H3>
<PRE>Math.E</PRE>
<H3>Property of</H3>
<P><A HREF="ref_m-q.htm#Math_object" Math_object">Math</A>
<H3>描述</H3>
<P>Because E is a constant, it is a read-only property of Math.
<H3>例子</H3>
<P>The following example displays Euler's constant:
<PRE>document.write("Euler's constant is " + Math.E)</PRE>
<H3>See also</H3>
<LI><A HREF="ref_h-l.htm#LN2_property" LN2_property">LN2</A>, <A HREF="ref_h-l.htm#LN10_property" LN10_property">LN10</A>, <A HREF="ref_h-l.htm#LOG2E_property" LOG2E_property">LOG2E</A>, <A HREF="ref_h-l.htm#LOG10E_property" LOG10E_property">LOG10E</A>, <A HREF="ref_m-q.htm#PI_property" PI_property">PI</A>, <A HREF="ref_s-s.htm#SQRT1_2_property" SQRT1_2_property">SQRT1_2</A>, <A HREF="ref_s-s.htm#SQRT2_property" SQRT2_property">SQRT2</A> properties
<!------------------------------------------------------------------------------------------------->
<HR>
<A NAME="elements_object"><H2><I>elements</I> array</H2> </A>
<P>An array of objects corresponding to form elements (such as checkbox, radio, and text objects) in source order.
<H3>語法</H3>
<PRE>
1. <I>formName</I>.elements[<I>index</I>]
2. <I>formName</I>.elements.length
</PRE>
<P><I>formName</I> is either the name of a form or an element in the <I>forms</I> array.
<BR><I>index</I> is an integer representing an object on a form.
<H3>Property of</H3>
<LI><A HREF="ref_f-g.htm#form_object" form_object">form</A>
<H3>描述</H3>
<P>You can reference a form's elements in your code by using the <I>elements</I> array. This array contains an entry for each object (button, checkbox, hidden, password, radio, reset, select, submit, text, or textarea object) in a form in source order. For example, if a form has a text field and two checkboxes, these elements are reflected as <TT><I>formName</I>.elements[0]</TT>, <TT><I>formName</I>.elements[1]</TT>, and <TT><I>formName</I>.elements[2]</TT>.
<P>Although you can also reference a form's elements by using the element's name (from the NAME attribute), the elements array provides a way to reference form objects programatically without using their names. For example, if the first object on the <I>userInfo</I> form is the <I>userName</I> text object, you can evaluate it in either of the following ways:
<PRE>
userInfo.userName.value
userInfo.elements[0].value
</PRE>
<P>To obtain the number of elements on a form, use the length property: <TT><I>formName</I>.elements.length</TT>. Each radio button in a radio object appears as a separate element in the <I>elements</I> array.
<P>Elements in the <I>elements</I> array are read-only. For example, the statement <TT><I>formName</I>.elements[0]="music"</TT> has no effect.
<P>The value of each element in the <I>elements</I> array is the full htm statement for the object.
<H3>Properties</H3>
<LI><A HREF="ref_h-l.htm#length_property" length_property">length</A> reflects the number of elements on a form
<H3>例子</H3>
<P>See the 例子 for the <A HREF="ref_m-q.htm#name_property" name_property">name</A> property.
<H3>See also</H3>
<LI><A HREF="ref_f-g.htm#form_object" form_object">form</A> object
<!------------------------------------------------------------------------------------------------->
<HR>
<A NAME="elements_property"><H2>elements property</H2></A>
<P>An array of objects corresponding to form elements (such as checkbox, radio, and text objects) in source order. See <A HREF="ref_d-e.htm#elements_object" elements_object"><I>elements</I></A> array.
<!------------------------------------------------------------------------------------------------->
<HR>
<A NAME="encoding_property"><H2>encoding property</H2></A>
<P>
A string specifying the MIME encoding of the form.
<H3>語法</H3>
<PRE><I>formName</I>.encoding</PRE>
<P><I>formName</I> is either the name of a form or an element in the <I>forms</I> array.
<H3>Property of</H3>
<P><A HREF="ref_f-g.htm#form_object" form_object">form</A>
<H3>描述</H3>
<P>The encoding property initially reflects the ENCTYPE attribute of the <FORM> tag; however, setting encoding overrides the ENCTYPE attribute.
<P>You can set the encoding property at any time.
<P>Certain values of the encoding property may require specific values for other form properties. See <A HREF="tppmsgs/msgs0.htm#3" tppabs="http://www.ics.uci.edu/pub/ietf/htm/rfc1867.txt" TARGET="_top">RFC 1867</A> for more information.
<H3>例子</H3>
<P>The following function returns the value of the <I>musicForm</I> encoding property:
<PRE>
function getEncoding() {
return document.musicForm.encoding
}
</PRE>
<H3>See also</H3>
<LI><A HREF="ref_a-c.htm#action_property" action_property">action</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="escape_method"><H2>escape function</H2></A>
<P>
Returns the ASCII encoding of an argument in the ISO Latin-1 character set.
<H3>語法</H3>
<PRE>escape("<I>string</I>")</PRE>
<P><I>string</I> is a non-alphanumeric string in the ISO Latin-1 character set, or a property of an existing object.
<H3>描述</H3>
<P>The escape function is not a method associated with any object, but is part of the language itself.
<P>The value returned by the escape function is a string of the form "%xx", where <I>xx</I> is the ASCII encoding of a character in the argument. If you pass the escape function an alphanumeric character, the escape function returns the same character.
<H3>例子</H3>
<P>The following example returns "%26"
<PRE>
escape("&")
</PRE>
<P>The following example returns "%21%23"
<PRE>
escape("!#")
</PRE>
<H3>See also</H3>
<LI><A HREF="ref_t-z.htm#unescape_method" unescape_method">unescape</A> function
<!------------------------------------------------------------------------------------------------>
<HR>
<A NAME="eval_method"> <H2>eval function</H2></A>
<P>
The eval function evaluates a string and returns a value.
<H3>語法</H3>
<PRE>eval(<I>string</I>)</PRE>
<I>string</I> is any string representing a JavaScript expression, statement, or sequence of statements. The expression can include variables and properties of existing objects.
<H3>描述</H3>
<P>The eval function is a built-in JavaScript function. It is not a method associated with any object, but is part of the language itself.
<P>The argument of the eval function is a string. Do not call eval to evaluate an arithmetic expression. JavaScript evaluates arithmetic expressions automatically. If the argument represents an expression, eval evaluates the expression. If the argument represents one or more JavaScript statements, eval performs the statements.
<P>If you construct an arithmetic expression as a string, you can use eval to evaluate it at a later time. For example, suppose you have a variable <I>x</I>. You can postpone evaluation of an expression involving <I>x</I> by assigning the string value of the expression, say <TT>"3 * x + 2"</TT>, to a variable, and then calling eval at a later point in your script.
<H3>例子</H3>
<P><B>Example 1.</B> Both of the write statements below display 42. The first evaluates the string "x + y + 1", and the second evaluates the string "42".
<PRE>
var x = 2
var y = 39
var z = "42"
document.write(eval("x + y + 1"), "<BR>")
document.write(eval(z), "<BR>")
</PRE>
<P><B>Example 2.</B> In the following example, the <I>getFieldName(n)</I> function returns the name of the nth form element as a string. The first statement assigns the string value of the third form element to the variable <I>field</I>. The second statement uses eval to display the value of the form element.
<PRE>
var field = getFieldName(3)
document.write("The field named ", field, " has value of ", eval(field + ".value"))
</PRE>
<P><B>Example 3.</B> The following example uses eval to evaluate the string <I>str</I>. This string consists of JavaScript statements that opens an alert dialog box and assigns z a value of 42 if x is five, and assigns zero to z otherwise. When the second statement is executed, eval will cause these statements to be performed, and it will also evaluate the set of statements and return the value that is assigned to z.
<PRE>
var str = "if (x == 5) {alert('z is 42'); z = 42;} else z = 0; "
document.write("<P>z is ", eval(str))
</PRE>
<P><B>Example 4.</B> In the following example, the <I>setValue()</I> function uses eval to assign the value of the variable <I>newValue</I> to the text field <I>textObject</I>.
<PRE>
function setValue (textObject, newValue) {
eval ("document.forms[0]." + textObject + ".value") = newValue
}
</PRE>
<!------------------------------------------------------------------------------------------------>
<HR>
<A NAME="exp_method"><H2>exp method</H2></A>
<P>
Returns e<SUP><I>number</I></SUP>, where <I>number</I> is the argument, and <I>e</I> is Euler's constant, the base of the natural logarithms.
<H3>語法</H3>
<PRE>Math.exp(<I>number</I>)</PRE>
<I>number</I> is any numeric expression or a property of an existing object.
<H3>Method of</H3>
<P><A HREF="ref_m-q.htm#Math_object" Math_object">Math</A>
<H3>例子</H3>
<PRE>
//Displays the value 2.718281828459045
document.write("The value of e<SUP>1</SUP> is " + Math.exp(1))
</PRE>
<H3>See also</H3>
<LI><A HREF="ref_h-l.htm#log_method" log_method">log</A>, <A HREF="ref_m-q.htm#pow_method" pow_method">pow</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 + -