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

📄 methods.html

📁 javascript中文教程
💻 HTML
📖 第 1 页 / 共 4 页
字号:
<H3>Syntax</H3>
<P>confirm("<I>message</I>")
<P>The argument <I>message</I> is any string.

<H3>Description</H3>
<P>Use the confirm method to ask the user to make a decision that requires either an OK or a Cancel. The <I>message</I> argument specifies a message that prompts the user for the decison. The confirm method returns true if the user chooses OK and false if the user chooses Cancel.

<H3>Applies to</H3>
<P><A HREF=objects.html#window_object>window</A>

<H3>Examples</H3>
<P>This example uses the confirm method in the confirmCleanUp function to confirm that the user of an application really wants to quit. If the user chooses OK, the custom cleanUp() function closes the application.
<PRE>
function confirmCleanUp() {
   if (confirm("Are you sure you want to quit this application?")) {
      cleanUp()
   }
}</PRE>
You can call the confirmCleanUp function in the onClick event handler of a form's pushbutton, as shown in the following example:
<PRE>&ltINPUT TYPE="button" VALUE="Quit" onClick="confirmCleanUp()"&gt</PRE>


<H3>See also</H3>
<LI><A HREF=#alert_method>alert</A>, <A HREF=#prompt_method>prompt</A> methods
<!------------------------------------------------------------------------------------------------>
<HR>
<A NAME="cos_method"><H2>cos method</H2></A>
<P>
Returns the cosine of its argument. The argument is in radians.

<H3>Syntax</H3>
<PRE>cos(<I>arg</I>)</PRE>

<H3>Applies to</H3>
<P><A HREF=objects.html#Math_object>Math</A>

<H3>Examples</H3>
<P>xxx Examples to be supplied.

<H3>See also</H3>
<LI><A HREF=#acos_method>acos</A>, <A HREF=#asin_method>asin</A>, <A HREF=#atan_method>atan</A>, <A HREF=#sin_method>sin</A>, <A HREF=#tan_method>tan</A> methods
<!------------------------------------------------------------------------------------------------>
<HR>
<A NAME="eval_method"> <H2>eval function</H2></A>
<P>
The eval function is a function built-in to JavaScript. It is not a method associated with any object, but is part of the language itself.


<H3>Syntax</H3>
<PRE>eval(<I>expression</I>)</PRE>


<H3>Description</H3>
<P>The eval function takes a JavaScript arthimetic expression as its argument and returns the value of the argument as a number.


<H3>Example</H3>
<P>Both of the uses of eval in the following example assign the value 42 to the variable result.
<PRE>x = 6
result = eval((3+3)*7)
result = eval(x*7)
</PRE>


<!------------------------------------------------------------------------------------------------>
<HR>
<A NAME="exp_method"><H2>exp method</H2></A>
<P>
Returns <I>e</I> to the power of its argument, i.e. e<SUP>x</SUP>, where <I>x</I> is the argument, and <I>e</I> is Euler's constant, the base of the natural logarithms.

<H3>Syntax</H3>
<PRE>exp(<I>arg</I>)</PRE>

<H3>Applies to</H3>
<P><A HREF=objects.html#Math_object>Math</A>

<H3>Examples</H3>
<P>xxx Examples to be supplied.

<H3>See also</H3>
<LI><A HREF=#log_method>log</A> method
<!------------------------------------------------------------------------------------------------>
<HR>
<A NAME="fixed_method"><H2>fixed method</H2></A>
<P>
Causes the calling string object to be displayed in fixed-pitch font in HTML by surrounding it with typewriter text tags, <TT> &ltfixed&gt ... &lt/fixed&gt.</TT>

<H3>Syntax</H3>
<PRE>fixed()</PRE>
<B>NOTE:</b> For Beta4, use TT() for this method.

<H3>Description</H3>
<P>xxx Description to be supplied.

<H3>Applies to</H3>
<P><A HREF=objects.html#string_object>string</A>

<H3>Examples</H3>
<P>xxx Examples to be supplied.
<!------------------------------------------------------------------------------------------------>
<HR>
<A NAME="floor_method"><H2>floor method</H2></A>
<P>
Returns the greatest integer less than or equal to its argument.

<H3>Syntax</H3>
<PRE>floor(<I>arg</I>)</PRE>

<H3>Applies to</H3>
<P><A HREF=objects.html#Math_object>Math</A>

<H3>Examples</H3>
<P>xxx Examples to be supplied.

<H3>See also</H3>
<LI><A HREF=#ceil_method>ceil</A> method
<!------------------------------------------------------------------------------------------------>
<HR>
<A NAME="focus_method"><H2>focus method</H2></A>
<P>
For password, text, and textArea, gives focus to the object.

<H3>Syntax</H3>
<PRE>focus()</PRE>

<H3>Description</H3>
<P>Use the focus method to navigate to a specific form element and give it focus. You can then either programatically enter a value in the element or let the user enter a value.

<H3>Applies to</H3>
<P><A HREF=objects.html#password_object>password</A>, <A HREF=objects.html#text_object>text</A>, <A HREF=objects.html#textArea_object>textArea</A>

<H3>Examples</H3>
<P>In the following example, the checkPassword function confirms that a user has entered a valid password. If the password is not valid, the focus method returns focus to the password field and the select method highlights it so the user can re-enter the password.
<PRE>
function checkPassword(userPass) {
   if (badPassword) {
      alert("Please enter your password again.")
      userPass.focus()
      userPass.select()
   }
}</PRE>
This example assumes that the password is defined as:
<PRE>&ltINPUT TYPE=password NAME=userPass&gt</PRE>

<H3>See also</H3>
<LI><A HREF=#blur_method>blur</A>, <A HREF=#select_method>select</A> methods
<!------------------------------------------------------------------------------------------------>
<HR>
<A NAME="fontcolor_method"><H2>fontcolor method</H2></A>
<P>
Causes the calling string object to be displayed in the specified color by surrounding it with HTML font color tags, <TT> &ltFONTCOLOR=color&gt ... &lt/FONTCOLOR&gt.</TT>

<H3>Syntax</H3>
<PRE>fontcolor(<I>color</I>)</PRE>
<P>The argument to the method, <I>color</I>, must be a string containing a hashmark (#) followed by a triplet of hexadecimal number pairs. These three pairs represent the red, green, and blue values for the desired color, respectively.

<H3>Description</H3>
<P>xxx Description to be supplied.

<H3>Applies to</H3>
<P><A HREF=objects.html#string_object>string</A>

<H3>Examples</H3>
<P>xxx Examples to be supplied.
<!------------------------------------------------------------------------------------------------>
<HR>
<A NAME="fontsize_method"><H2>fontsize method</H2></A>
<P>
Causes the calling string object to be displayed in the specified font size by surrounding it with HTML font size tags, <TT> &ltFONTSIZE=size&gt ... &lt/FONTSIZE&gt.</TT>

<H3>Syntax</H3>
<PRE>fontsize(<I>size</I>)</PRE>
<P>The argument to the method, <I>size</I>, must be an integer between one and seven.

<H3>Description</H3>
<P>xxx Description to be supplied.

<H3>Applies to</H3>
<P><A HREF=objects.html#string_object>string</A>

<H3>Examples</H3>
<P>xxx Examples to be supplied.

<H3>See also</H3>
<LI><A HREF=#big_method>big</A>, <A HREF=#small_method>small</A> methods
<!------------------------------------------------------------------------------------------------>
<HR>
<A NAME="forward_method"><H2>forward method</H2></A>
<P>
Loads the next URL in the history list.

<H3>Syntax</H3>
<PRE>forward()</PRE>

<H3>Description</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>go(1)</TT>.

<H3>Applies to</H3>
<P><A HREF=objects.html#history_object>history</A>

<H3>Examples</H3>
<P>xxx Examples to be supplied.

<H3>See also</H3>
<LI><A HREF=#back_method>back</A>, <A HREF=#go_method>go</A> methods
<!------------------------------------------------------------------------------------------------>
<HR>
<A NAME="getDate_method"><H2>getDate method</H2></A>

<H3>Syntax</H3>
<CODE>dateObj.getDate()</CODE>
<P>
where <code>dateObj</code> is a date object.

<H3>Description</H3>
<P>Returns the day of the month for the date object, an integer between 1 and 31.

<H3>Applies to</H3>
<P><A HREF=objects.html#Date_object>Date</A>

<H3>Examples</H3>
<P>
The second statement below assigns the value 25 to the variable day, based on the value of the date object Xmas95.
<PRE>
Xmas95 = new Date("December 25, 1995 23:15:00")
day = Xmas95.getDate()
</PRE>

<H3>See also</H3>
<LI>xxx To be supplied.
<!------------------------------------------------------------------------------------------------>
<HR>
<A NAME="getDay_method"><H2>getDay method</H2></A>

<H3>Syntax</H3>
<CODE>dateObj.getDay() </CODE>
<P>
where <code>dateObj</code> is a date object.

<H3>Description</H3>
<P>
Returns the day of the week for the date object, an integer corresponding
to the day of the week: zero for Sunday, one for Monday, two for Tuesday, 
and so on. 

<H3>Applies to</H3>
<P><A HREF=objects.html#Date_object>Date</A>

<H3>Examples</H3>
<P>
The second statement below assigns the value 1 to weekday, 
based on the value of the date object Xmas95. This is because December 25, 1995 is a Monday.
<PRE>
Xmas95 = new Date("December 25, 1995 23:15:00")
weekday = Xmas95.getDay()
</PRE>


<H3>See also</H3>
<LI>xxx To be supplied.
<!------------------------------------------------------------------------------------------------>
<HR>
<A NAME="getHours_method"><H2>getHours method</H2></A>
<H3>Syntax</H3>
<PRE>dateObj.getHours()</PRE>
<P>
where <code>dateObj</code> is a date object.

<H3>Description</H3>
<P>
Returns the hour for the date object, an integer between 0 and 23.

<H3>Applies to</H3>
<P><A HREF=objects.html#Date_object>Date</A>

<H3>Examples</H3>
<P>
The second statement below assigns the value 23 to the variable hours, based on the value of the date object Xmas95.
<PRE>
Xmas95 = new Date("December 25, 1995 23:15:00")
hours = Xmas95.getHours()
</PRE>


<H3>See also</H3>
<LI>xxx To be supplied.
<!------------------------------------------------------------------------------------------------>
<HR>
<A NAME="getMinutes_method"><H2>getMinutes method</H2></A>
<H3>Syntax</H3>
<CODE>dateObjgetMinute() </CODE>
<P>
where <code>dateObj</code> is a date object.

<H3>Description</H3>
<P>
Returns the minutes in the date object, an integer between 0 and 59.

<H3>Applies to</H3>
<P><A HREF=objects.html#Date_object>Date</A>

<H3>Examples</H3>
<P>
The second statement below assigns the value 15 to the variable minutes, based on the value of the date object Xmas95.
<PRE>
Xmas95 = new Date("December 25, 1995 23:15:00")
minutes = Xmas95.getMinutes()
</PRE>

<H3>See also</H3>
<LI>xxx To be supplied.
<!------------------------------------------------------------------------------------------------>
<HR>
<A NAME="getMonth_method"><H2>getMonth method</H2></A>
<H3>Syntax</H3>
<CODE>dateObj.getMonth() </CODE>
<P>
where <code>dateObj</code> is a date object.

<H3>Description</H3>
<P>
Returns the month in the date object, an integer between zero and eleven. Zero corresponds to January, one to Februrary, and so on.

<H3>Applies to</H3>
<P><A HREF=objects.html#Date_object>Date</A>

<H3>Examples</H3>
<P>
The second statement below assigns the value 11 to the variable month, based on the value of the date object Xmas95.
<PRE>
Xmas95 = new Date("December 25, 1995 23:15:00")
month = Xmas95.getDate()
</PRE>


<H3>See also</H3>
<LI>xxx To be supplied.
<!------------------------------------------------------------------------------------------------>
<HR>
<A NAME="getSeconds_method"><H2>getSeconds method</H2></A>
<H3>Syntax</H3>
<P><CODE>dateObj.getSeconds() </CODE>
<P>
where <code>dateObj</code> is a date object.

<H3>Description</H3>
<P>
Returns the seconds in the current time, an integer between 0 and 59.

<H3>Applies to</H3>
<P><A HREF=objects.html#Date_object>Date</A>

<H3>Examples</H3>
<P>
The second statement below assigns the value 30 to the variable secs, 
based on the value of the date object Xmas95.
<PRE>
Xmas95 = new Date("December 25, 1995 23:15:30")
secs = Xmas95.getSeconds()
</PRE>

<H3>See also</H3>
<LI>xxx To be supplied.

<!------------------------------------------------------------------------------------------------>
<HR>
<A NAME="getTime_method"><H2>getTime method</H2></A>
<H3>Syntax</H3>
<CODE>dateObj.getTime() </CODE>
<P>
where <code>dateObj</code> is a date object.

<H3>Description</H3>
<P>
Returns the numeric value for the date object.
This number is the number of milliseconds since the epoch (1 January 1970 00:00:00)
You can use this method to help assign a date and time to another date object.

<H3>Applies to</H3>
<P><A HREF=objects.html#Date_object>Date</A>

<H3>Examples</H3>
<P>
The following example assigns the date value of theBigDay to sameAsBigDay.

<PRE>
theBigDay = new Date("July 1, 1999")
sameAsBigDay = new Date();
sameAsBigDay.setTime(theBigDay.getTime())
</PRE>

<H3>See also</H3>
<LI>xxx To be supplied.

<!----------------------------------------------------------------->
<HR>
<A NAME="getTimezoneOffset_method"><H2>getTimezoneOffset method</H2></A>

<H3>Syntax</H3>
<CODE>dateObj.getTimezoneOffset()</CODE>
<P>
where <code>dateObj</code> is a date object.

<H3>Description</H3>
<P>
Return the time zone offset in minutes for the current locale, i.e. the 
difference between the local time and GMT. 
This value would be a constant except for daylight savings time. 

<H3>Applies to</H3>
<P><A HREF=objects.html#Date_object>Date</A>

<H3>Examples</H3>

<PRE>
x = new Date();
currentTimeZoneOffsetInHours = x.getTimezoneOffset()/60;
</PRE>

<H3>See also</H3>
<LI>xxx To be supplied.

<!------------------------------------------------------------------------------------------------>
<HR>
<A NAME="getYear_method"><H2>getYear method</H2></A>
<H3>Syntax</H3>
<P><PRE>getyear()</PRE>

<H3>Description</H3>
<P>
Returns the year in the date object, less 1900.

<H3>Applies to</H3>
<P><A HREF=objects.html#Date_object>Date</A>

<H3>Examples</H3>
<P>
The second statement below assigns the value 95 to the variable year, based on the value of the date object Xmas95.
<PRE>
Xmas95 = new Date("December 25, 1995 23:15:00")
year = Xmas95.getYear()
</PRE>


<H3>See also</H3>
<LI>xxx To be supplied.
<!------------------------------------------------------------------------------------------------>
<HR>
<A NAME="go_method"><H2>go method</H2></A>
<P>
The argument delta is an integer. If <i>delta</i>&nbsp; is greater than zero, then it loads the URL that is that number of entries forward in the history list; otherwise, it loads the URL that is that number of entries backward in the history list.
<P>
The argument string is a string. Go to the newest history entry whose title or URL contains string as a substring; substring matching is case-insensitive.

<H3>Syntax</H3>
<PRE>go(delta | "string")</PRE>

<H3>Description</H3>
<P>xxx Description to be supplied.

<H3>Applies to</H3>
<P><A HREF=objects.html#history_object>history</A>

⌨️ 快捷键说明

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