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

📄 ref_s-s.htm

📁 javascript函数大全HTML javascript函数大全HTML
💻 HTM
📖 第 1 页 / 共 4 页
字号:

<H3>语法</H3>
<PRE><I>timeoutID</I>=setTimeout(<I>expression</I>, <I>msec</I>)</PRE>
<P><I>timeoutID</I> is an identifier that is used only to cancel the evaluation with the clearTimeout method.
<BR><I>expression</I> is a string expression or a property of an existing object.
<BR><I>msec</I> is a numeric value, numeric string, or a property of an existing object in millisecond units.

<H3>方法</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 setTimeout method evaluates an expression after a specified amount of time. It does not evaluate the expression repeatedly. For example, if a setTimeout method specifies 5 seconds, the expression is evaluated after 5 seconds, not every 5 seconds.


<H3>例子</H3>
<P><B>Example 1.</B> The following example displays an alert message 5 seconds (5,000 milliseconds) after the user clicks a button. If the user clicks the second button before the alert message is displayed, the timeout is canceled and the alert does not display.

<XMP>
<SCRIPT LANGUAGE="JavaScript">
function displayAlert() {
   alert("5 seconds have elapsed since the button was clicked.")
}
</SCRIPT>
<BODY>
<FORM>
Click the button on the left for a reminder in 5 seconds; 
click the button on the right to cancel the reminder before 
it is displayed.
<P>
<INPUT TYPE="button" VALUE="5-second reminder"
   NAME="remind_button"
   onClick="timerID=setTimeout('displayAlert()',5000)">
<INPUT TYPE="button" VALUE="Clear the 5-second reminder"
   NAME="remind_disable_button"
   onClick="clearTimeout(timerID)">
</FORM>
</BODY>
</XMP>

<P><B>Example 2.</B> The following example displays the current time in a text object. The showtime() function, which is called recursively, uses the setTimeout method update the time every second.
<XMP>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
var timerID = null
var timerRunning = false
function stopclock(){
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}
function startclock(){
     // Make sure the clock is stopped
    stopclock()
    showtime()
}
function showtime(){
    var now = new Date()
    var hours = now.getHours()
    var minutes = now.getMinutes()
    var seconds = now.getSeconds()
    var timeValue = "" + ((hours > 12) ? hours - 12 : hours)
    timeValue  += ((minutes < 10) ? ":0" : ":") + minutes
    timeValue  += ((seconds < 10) ? ":0" : ":") + seconds
    timeValue  += (hours >= 12) ? " P.M." : " A.M."
    document.clock.face.value = timeValue 
    timerID = setTimeout("showtime()",1000)
    timerRunning = true
}
//-->
</SCRIPT>
</HEAD>

<BODY onLoad="startclock()">
<FORM NAME="clock" onSubmit="0">
    <INPUT TYPE="text" NAME="face" SIZE=12 VALUE ="">
</FORM>
</BODY>
</XMP>


<H3>相关</H3>
<LI><A HREF="ref_a-c.htm#clearTimeout_method" clearTimeout_method">clearTimeout</A> method
<!------------------------------------------------------------------------------------------------>
<HR>
<A NAME="setYear_method"><H2>setYear method</H2></A>
<P>
Sets the year for a specified date.

<H3>语法</H3>
<PRE><I>dateObjectName</I>.setYear(<I>yearValue</I>)</PRE>
<P><I>dateObjectName</I> is either the name of a date object or a property of an existing object.
<BR><I>yearValue</I> is an integer greater than 1900 or a property of an existing object.

<H3>方法</H3>
<P><A HREF="ref_d-e.htm#Date_object" Date_object">Date</A>

<H3>例子</H3>
<PRE>
theBigDay.setYear(96)
</PRE>

<H3>相关</H3>
<LI><A HREF="ref_f-g.htm#getYear_method" getYear_method">getYear</A> method
<!------------------------------------------------------------------------------------------------>
<HR>
<A NAME="sin_method"><H2>sin method</H2></A>
<P>
Returns the sine of a number.

<H3>语法</H3>
<PRE>Math.sin(<I>number</I>)</PRE>
<P><I>number</I> is a numeric expression or a property of an existing object, representing the size of an angle in radians.

<H3>方法</H3>
<P><A HREF="ref_m-q.htm#Math_object" Math_object">Math</A>

<H3>描述</H3>
<P>The sin method returns a numeric value between -1 and 1, which represents the sine of the angle.

<H3>例子</H3>
<PRE>
//Displays the value 1
document.write("The sine of pi/2 radians is " +
   Math.sin(Math.PI/2))

//Displays the value 1.224606353822377e-016
document.write("&ltP&gtThe sine of pi radians is " +
   Math.sin(Math.PI))

//Displays the value 0
document.write("&ltP&gtThe sine of 0 radians is " +
   Math.sin(0))
</PRE>

<H3>相关</H3>
<LI><A HREF="ref_a-c.htm#acos_method" acos_method">acos</A>, <A HREF="ref_a-c.htm#asin_method" asin_method">asin</A>, <A HREF="ref_a-c.htm#atan_method" atan_method">atan</A>, <A HREF="ref_a-c.htm#cos_method" cos_method">cos</A>, <A HREF="ref_t-z.htm#tan_method" tan_method">tan</A> methods
<!------------------------------------------------------------------------------------------------>
<HR>
<A NAME="small_method"><H2>small method</H2></A>
<P>
Causes a string to be displayed in a small font as if it were in a &ltSMALL&gt tag.

<H3>语法</H3>
<PRE><I>stringName</I>.small()</PRE>
<P><I>stringName</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 small method with the write or writeln methods to format and display a string in a document.

<H3>例子</H3>
The following example uses string methods to change the size of a string:
<PRE>
var worldString="Hello, world"

document.write(worldString.small())
document.write("&ltP&gt" + worldString.big())
document.write("&ltP&gt" + worldString.fontsize(7))
</PRE>

<P>The previous example produces the same output as the following htm:
<PRE>
<TT>&ltSMALL&gtHello, world&lt/SMALL&gt</TT>
<TT>&ltP&gt&ltBIG&gtHello, world&lt/BIG&gt</TT>
<TT>&ltP&gt&ltFONTSIZE=7&gtHello, world&lt/FONTSIZE&gt</TT>
</PRE>

<H3>相关</H3>
<LI><A HREF="ref_a-c.htm#big_method" big_method">big</A>, <A HREF="ref_f-g.htm#fontsize_method" fontsize_method">fontsize</A> methods
<!------------------------------------------------------------------------------------------------>
<HR>
<A NAME="sqrt_method"><H2>sqrt method</H2></A>
<P>
Returns the square root of a number.

<H3>语法</H3>
<PRE>Math.sqrt(<I>number</I>)</PRE>
<I>number</I> is any non-negative numeric expression or a property of an existing object.

<H3>方法</H3>
<P><A HREF="ref_m-q.htm#Math_object" Math_object">Math</A>

<H3>描述</H3>
<P>If the value of <I>number</I> is outside the suggested range, the return value is always 0.

<H3>例子</H3>
<PRE>
//Displays the value 3
document.write("The square root of 9 is " + Math.sqrt(9))

//Displays the value 1.414213562373095
document.write("&ltP&gtThe square root of 2 is " + Math.sqrt(2))

//Displays the value 0 because the argument is out of range
document.write("&ltP&gtThe square root of -1 is " + Math.sqrt(-1))
</PRE>

<!------------------------------------------------------------------------------------------------>
<HR>
<A NAME="SQRT1_2_property"><H2>SQRT1_2 property</H2></A>
<P>
The square root of one-half; equivalently, one over the square root of two, approximately 0.707.

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

<H3>Property of</H3>
<P><A HREF="ref_m-q.htm#Math_object" Math_object">Math</A>

<H3>描述</H3>
<P>Because SQRT1_2 is a constant, it is a read-only property of Math.

<H3>例子</H3>
<P>The following example displays 1 over the square root of 2:
<PRE>document.write("1 over the square root of 2 is " + Math.SQRT1_2)</PRE>

<H3>相关</H3>
<LI><A HREF="ref_d-e.htm#E_property" E_property">E</A>, <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#SQRT2_property" SQRT2_property">SQRT2</A> properties
<!------------------------------------------------------------------------------------------------->
<HR>
<A NAME="SQRT2_property"><H2>SQRT2 property</H2></A>
<P>
The square root of two, approximately 1.414.

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

<H3>Property of</H3>
<P><A HREF="ref_m-q.htm#Math_object" Math_object">Math</A>

<H3>描述</H3>
<P>Because SQRT2 is a constant, it is a read-only property of Math.

<H3>例子</H3>
<P>The following example displays the square root of 2:
<PRE>document.write("The square root of 2 is " + Math.SQRT2)</PRE>

<H3>相关</H3>
<LI><A HREF="ref_d-e.htm#E_property" E_property">E</A>, <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> properties
<!------------------------------------------------------------------------------------------------->
<HR>
<A NAME="status_property"><H2>status property</H2></A>
<P>
Specifies a priority or transient message in the status bar at the bottom of the window, such as the message that appears when a mouseOver event occurs over an anchor.

<H3>语法</H3>
<PRE><I>windowReference</I>.status</PRE>
<P><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>
<P><A HREF="ref_t-z.htm#window_object" window_object">window</A>

<H3>描述</H3>
<P>Do not confuse the status property with the defaultStatus property. The defaultStatus property reflects the default message displayed in the status bar.

<P>You can set the status property at any time. You must return true if you want to set the status property in the onMouseOver event handler.

<H3>例子</H3>
<P>
Suppose you have created a JavaScript function called pickRandomURL() that lets you select a URL at random. You can use the onClick event handler of an anchor to specify a value for the HREF attribute of the anchor dynamically, and the onMouseOver event handler to specify a custom message for the window in the status property:
<XMP><A HREF=""
   onClick="this.href=pickRandomURL()"
   onMouseOver="self.status='Pick a random URL'; return true">
Go!</A></XMP>
<P>In the above example, the status property of the window is assigned to the window's self property, as <TT>self.status</TT>. As this example shows, you must return true to set the status property in the onMouseOver event handler.

<H3>相关</H3>
<LI><A HREF="ref_d-e.htm#defaultStatus_property" defaultStatus_property">defaultStatus</A> property
<!------------------------------------------------------------------------------------------------->
<HR>
<A NAME="strike_method"><H2>strike method</H2></A>
<P>
Causes a string to be displayed as struck out text as if it were in a &ltSTRIKE&gt tag.

<H3>语法</H3>
<PRE><I>stringName</I>.strike()</PRE>
<P><I>stringName</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 strike method with the write or writeln methods to format and display a string in a document.

<H3>例子</H3>
The following example uses string methods to change the formatting of a string:
<PRE>
var worldString="Hello, world"

document.write(worldString.blink())
document.write("&ltP&gt" + worldString.bold())
document.write("&ltP&gt" + worldString.italics())
document.write("&ltP&gt" + worldString.strike())
</PRE>

<P>The previous example produces the same output as the following htm:
<PRE>
<TT>&ltBLINK&gtHello, world&lt/BLINK&gt</TT>

⌨️ 快捷键说明

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