📄 ref_a-c.htm
字号:
<P>
Removes focus from the specified object.
<H3>语法</H3>
<PRE>
1. <I>passwordName</I>.blur()
2. <I>selectName</I>.blur()
3. <I>textName</I>.blur()
4. <I>textareaName</I>.blur()
</PRE>
<P><I>passwordName</I> is either the value of the NAME attribute of a password 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>textName</I> is either the value of the NAME attribute of a text object or an element in the <I>elements</I> array.
<BR><I>textareaName</I> is either the value of the NAME attribute of a textarea object or an element in the <I>elements</I> array.
<H3>用法</H3>
<P><A HREF="ref_m-q.htm#password_object" password_object">password</A>, <A HREF="ref_s-s.htm#select_object" select_object">select</A>, <A HREF="ref_t-z.htm#text_object" text_object">text</A>, <A HREF="ref_t-z.htm#textarea_object" textarea_object">textarea</A>
<H3>描述</H3>
<P>Use the blur method to remove focus from a specific form element.
<H3>例子</H3>
<P>The following example removes focus from the password element <I>userPass</I>:
<PRE>
userPass.blur()
</PRE>
This example assumes that the password is defined as:
<PRE><INPUT TYPE="password" NAME="userPass"></PRE>
<H3>See also</H3>
<LI><A HREF="ref_f-g.htm#focus_method" focus_method">focus</A>, <A HREF="ref_s-s.htm#select_method" select_method">select</A> methods
<!------------------------------------------------------------------------------------------------>
<HR>
<A NAME="bold_method"><H2>bold method</H2></A>
<P>
Causes a string to be displayed as bold as if it were in a <B> tag.
<H3>语法</H3>
<PRE><I>stringName</I>.bold()</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 bold 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("<P>" + worldString.bold())
document.write("<P>" + worldString.italics())
document.write("<P>" + worldString.strike())
</PRE>
<P>The previous example produces the same output as the following htm:
<PRE>
<TT><BLINK>Hello, world</BLINK></TT>
<TT><P><B>Hello, world</B></TT>
<TT><P><I>Hello, world</I></TT>
<TT><P><STRIKE>Hello, world</STRIKE></TT>
</PRE>
<H3>See also</H3>
<LI><A HREF="ref_a-c.htm#blink_method" blink_method">blink</A>, <A HREF="ref_h-l.htm#italics_method" italics_method">italics</A>, <A HREF="ref_s-s.htm#strike_method" strike_method">strike</A> methods
<!------------------------------------------------------------------------------------------------>
<HR>
<A NAME="button_object"><H2>button object</H2></A>
<P>A pushbutton on an htm form.
<H3>语法</H3>
<P>To define a button:
<PRE>
<INPUT
TYPE="button"
NAME="<I>buttonName</I>"
VALUE="<I>buttonText</I>"
[onClick="<I>handlerText</I>"]>
</PRE>
<I>NAME="buttonName"</I> specifies the name of the button object. You can access this value using the name property.
<BR><I>VALUE="buttonText"</I> specifies the label to display on the button face. You can access this value using the value property.
<P>To use a button object's properties and methods:
<PRE>
1. <I>buttonName</I>.<I>propertyName</I>
2. <I>buttonName</I>.<I>methodName</I>(<I>parameters</I>)
3. <I>formName</I>.elements[<I>index</I>].<I>propertyName</I>
4. <I>formName</I>.elements[<I>index</I>].<I>methodName</I>(<I>parameters</I>)
</PRE>
<I>buttonName</I> is the value of the NAME attribute of a button object.
<BR><I>formName</I> is either the value of the NAME attribute of a form object or an element in the <I>forms</I> array.
<BR><I>index</I> is an integer representing a button object on a form.
<BR><I>propertyName</I> is one of the properties listed below.
<BR><I>methodName</I> is one of the methods listed below.
<H3>Property of</H3>
<LI><A HREF="ref_f-g.htm#form_object" form_object">form</A>
<H3>描述</H3>
<P>A button object on a form looks as follows:
<FORM>
<P><INPUT TYPE="button" VALUE="Click me">
</FORM>
<P>A button object is a form element and must be defined within a <FORM> tag.
<P>The button object is a custom button that you can use to perform an action you define. The button executes the script specified by its onClick event handler.
<H3>Properties</H3>
<LI><A HREF="ref_m-q.htm#name_property" name_property">name</A> reflects the NAME attribute
<LI><A HREF="ref_t-z.htm#value_property" value_property">value</A> reflects the VALUE attribute
<H3>Methods</H3>
<LI><A HREF="ref_a-c.htm#click_method" click_method">click</A>
<H3>Event handlers</H3>
<LI><A HREF="ref_m-q.htm#onClick_event" onClick_event">onClick</A>
<H3>例子</H3>
<P>The following example creates a button named <I>calcButton</I>. The text "Calculate" is displayed on the face of the button. When the button is clicked, the function <I>calcFunction()</I> is called.
<XMP>
<INPUT TYPE="button" VALUE="Calculate" NAME="calcButton"
onClick="calcFunction(this.form)">
</XMP>
<H3>See also</H3>
<LI><A HREF="ref_f-g.htm#form_object" form_object">form</A>, <A HREF="ref_r-r.htm#reset_object" reset_object">reset</A>, and <A HREF="ref_s-s.htm#submit_object" submit_object">submit</A> objects
<!------------------------------------------------------------------------------------------------->
<HR>
<A NAME="ceil_method"><H2>ceil method</H2></A>
<P>
Returns the least integer greater than or equal to a number.
<H3>语法</H3>
<PRE>Math.ceil(<I>number</I>)</PRE>
<P><I>number</I> is any 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>
<PRE>
//Displays the value 46
document.write("The ceil of 45.95 is " + Math.ceil(45.95))
//Displays the value -45
document.write("<P>The ceil of -45.95 is " + Math.ceil(-45.95))
</PRE>
<H3>See also</H3>
<LI><A HREF="ref_f-g.htm#floor_method" floor_method">floor</A> method
<!------------------------------------------------------------------------------------------------>
<HR>
<A NAME="charAt_method"><H2>charAt method</H2></A>
<P>
Returns the character at the specified <I>index</I>.
<H3>语法</H3>
<PRE><I>stringName</I>.charAt(<I>index</I>)</PRE>
<P><I>stringName</I> is any string or a property of an existing object.
<BR><I>index</I> is any integer from 0 to <I>stringName</I>.length - 1, 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>Characters in a string are indexed from left to right. The index of the first character is 0, and the index of the last character is <I>stringName</I>.length - 1. If the <I>index</I> you supply is out of range, JavaScript returns an empty string.
<H3>例子</H3>
The following example displays characters at different locations in the string "Brave new world".
<PRE>
var anyString="Brave new world"
document.write("The character at index 0 is " + anyString.charAt(0))
document.write("The character at index 1 is " + anyString.charAt(1))
document.write("The character at index 2 is " + anyString.charAt(2))
document.write("The character at index 3 is " + anyString.charAt(3))
document.write("The character at index 4 is " + anyString.charAt(4))
</PRE>
<H3>See also</H3>
<LI><A HREF="ref_h-l.htm#indexOf_method" indexOf_method">indexOf</A>, <A HREF="ref_h-l.htm#lastIndexOf_method" lastIndexOf_method">lastIndexOf</A> methods
<!------------------------------------------------------------------------------------------------>
<HR>
<A NAME="checkbox_object"> <H2>checkbox object</H2></A>
<P>A checkbox on an htm form. A checkbox is a toggle switch that lets the user set a value on or off.
<H3>语法</H3>
<P>To define a checkbox, use standard htm 语法 with the addition of the onClick event handler:
<PRE><INPUT
TYPE="checkbox"
NAME="<I>checkboxName</I>"
VALUE="<I>checkboxValue</I>"
[CHECKED]
[onClick="<I>handlerText</I>"]>
<I>textToDisplay</I>
</PRE>
<I>NAME="checkboxName"</I> specifies the name of the checkbox object. You can access this value using the name property.
<BR><I>VALUE="checkboxValue"</I> specifies a value that is returned to the server when the checkbox is selected and the form is submitted. This defaults to "on". You can access this value using the value property.
<BR><I>CHECKED</I> specifies that the checkbox is displayed as checked. You can access this value using the defaultChecked property.
<BR><I>textToDisplay</I> specifies the label to display beside the checkbox.
<P>To use a checkbox object's properties and methods:
<PRE>
1. <I>checkboxName</I>.<I>propertyName</I>
2. <I>checkboxName</I>.<I>methodName</I>(<I>parameters</I>)
3. <I>formName</I>.elements[<I>index</I>].<I>propertyName</I>
4. <I>formName</I>.elements[<I>index</I>].<I>methodName</I>(<I>parameters</I>)
</PRE>
<I>checkboxName</I> is the value of the NAME attribute of a checkbox object.
<BR><I>formName</I> is either the value of the NAME attribute of a form object or an element in the <I>forms</I> array.
<BR><I>index</I> is an integer representing a checkbox object on a form.
<BR><I>propertyName</I> is one of the properties listed below.
<BR><I>methodName</I> is one of the methods listed below.
<H3>Property of</H3>
<LI><A HREF="ref_f-g.htm#form_object" form_object">form</A>
<H3>描述</H3>
<P>A checkbox object on a form looks as follows:
<FORM>
<P><INPUT TYPE="checkbox" CHECKED> Overnight delivery
</FORM>
<P>A checkbox object is a form element and must be defined within a <FORM> tag.
<P>Use the checked property to specify whether the checkbox is currently checked. Use the defaultChecked property to specify whether the checkbox is checked when the form is loaded.
<H3>Properties</H3>
<LI><A HREF="ref_a-c.htm#checked_property" checked_property">checked</A> lets you programatically check a checkbox
<LI><A HREF="ref_d-e.htm#defaultChecked_property" defaultChecked_property">defaultChecked</A> reflects the CHECKED attribute
<LI><A HREF="ref_m-q.htm#name_property" name_property">name</A> reflects the NAME attribute
<LI><A HREF="ref_t-z.htm#value_property" value_property">value</A> reflects the VALUE attribute
<H3>Methods</H3>
<LI><A HREF="ref_a-c.htm#click_method" click_method">click</A>
<H3>Event handlers</H3>
<LI><A HREF="ref_m-q.htm#onClick_event" onClick_event">onClick</A>
<H3>例子</H3>
<P><B>Example 1.</B> The following example displays a group of four checkboxes that all appear checked by default.
<XMP>
<B>Specify your music preferences (check all that apply):</B>
<BR><INPUT TYPE="checkbox" NAME="musicpref_rnb" CHECKED> R&B
<BR><INPUT TYPE="checkbox" NAME="musicpref_jazz" CHECKED> Jazz
<BR><INPUT TYPE="checkbox" NAME="musicpref_blues" CHECKED> Blues
<BR><INPUT TYPE="checkbox" NAME="musicpref_newage" CHECKED> New Age
</XMP>
<P><B>Example 2.</B> The following example contains a form with three text boxes and one checkbox. The checkbox lets the user choose whether the text fields are converted to upper case. Each text field has an onChange event handler that converts the field value to upper case if the checkbox is checked. The checkbox has an onClick event handler that converts all fields to upper case when the user checks the checkbox.
<XMP>
<htm>
<HEAD>
<TITLE>Checkbox object example</TITLE>
</HEAD>
<SCRIPT>
function convertField(field) {
if (document.form1.convertUpper.checked) {
field.value = field.value.toUpperCase()}
}
function convertAllFields() {
document.form1.lastName.value = document.form1.lastName.value.toUpperCase()
document.form1.firstName.value = document.form1.firstName.value.toUpperCase()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -