📄 ref_s-s.htm
字号:
<htm><title>网络时空——网页制作</title>
<link rel="shortcut icon" href="../../../../ccisn.ico">
<link href="../../../../common.css" type="text/css" rel="stylesheet"><style type="text/css">
<!--
td,p,div {font-size:9pt;font-family:宋体;}
BODY { font-family:宋体; margin-left:0; margin-top:0; font-size:9pt; background-color:#ffffff;}
A { font-size: 9pt;color:#0000aa; text-decoration:underline;font-family:宋体; }
A:hover,A:active{ color:#FF8019; text-decoration:underline;}
A.top{color:#ffffff;font-size:9pt}
-->
</style>
<body bgcolor="#ffffff" text="#000000" link="#003399" alink="#ff9900" vlink="#000000" background="../../../images/b01.jpg">
<A NAME="search_property"><H2>search property</H2></A>
<P>
A string beginning with a question mark that specifies any query information in the URL.
<H3>语法</H3>
<PRE>
1. links[<I>index</I>].search
2. location.search
</PRE>
<P><I>index</I> is an integer representing a link object.
<H3>Property of</H3>
<P><A HREF="ref_h-l.htm#link_object" link_object">link</A>, <A HREF="ref_h-l.htm#location_object" location_object">location</A>
<H3>描述</H3>
<P>The search property specifies a portion of the URL.
<P>You can set the search property at any time, although it is safer to set the href property to change a location. If the search that you specify cannot be found in the current location, you will get an error.
<P>See Section 3.3 of <A HREF="tppmsgs/msgs0.htm#12" tppabs="http://www.cis.ohio-state.edu/htbin/rfc/rfc1738.htm" TARGET="_top">RFC 1738</A> for complete information about the search.
<H3>例子</H3>
<P>In the following example, the <TT>window.open</TT> statement creates a window called <I>newWindow</I> and loads the specified URL into it. The <TT>document.write</TT> statements display all the properties of <TT>newWindow.location</TT> in a window called <I>msgWindow</I>.
<PRE>
newWindow=window.open
("http://guide-p.infoseek.com/WW/NS/Titles?qt=RFC+1738+&col=WW")
msgWindow.document.write("newWindow.location.href = " +
newWindow.location.href + "<P>")
msgWindow.document.write("newWindow.location.protocol = " +
newWindow.location.protocol + "<P>")
msgWindow.document.write("newWindow.location.host = " +
newWindow.location.host + "<P>")
msgWindow.document.write("newWindow.location.hostName = " +
newWindow.location.hostName + "<P>")
msgWindow.document.write("newWindow.location.port = " +
newWindow.location.port + "<P>")
msgWindow.document.write("newWindow.location.pathname = " +
newWindow.location.pathname + "<P>")
msgWindow.document.write("newWindow.location.search = " +
newWindow.location.search + "<P>")
msgWindow.document.write("newWindow.location.hash = " +
newWindow.location.hash + "<P>")
msgWindow.document.close()
</PRE>
<P>The previous example displays the following output:
<PRE>
newWindow.location.href =
http://guide-p.infoseek.com/WW/NS/Titles?qt=RFC+1738+&col=WW
newWindow.location.protocol = http:
newWindow.location.host = guide-p.infoseek.com
newWindow.location.hostName = guide-p.infoseek.com
newWindow.location.port =
newWindow.location.pathname = /WW/NS/Titles
newWindow.location.search = ?qt=RFC+1738+&col=WW
newWindow.location.hash =
</PRE>
<H3>相关</H3>
<LI><A HREF="ref_h-l.htm#hash_property" hash_property">hash</A>, <A HREF="ref_h-l.htm#host_property" host_property">host</A>, <A HREF="ref_h-l.htm#hostname_property" hostname_property">hostname</A>, <A HREF="ref_h-l.htm#href_property" href_property">href</A>, <A HREF="ref_m-q.htm#pathname_property" pathname_property">pathname</A>, <A HREF="ref_m-q.htm#port_property" port_property">port</A>, <A HREF="ref_m-q.htm#protocol_property" protocol_property">protocol</A> properties
<!------------------------------------------------------------------------------------------------->
<HR>
<A NAME="select_method"><H2>select method</H2></A>
<P>
Selects the input area of the specified password, text, or textarea object.
<H3>语法</H3>
<PRE>
1. <I>passwordName</I>.select()
2. <I>textName</I>.select()
3. <I>textareaName</I>.select()
</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>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_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 select method to highlight the input area of a form element. You can use the select method with the focus method to highlight a field and position the cursor for a user response.
<H3>例子</H3>
<P>In the following example, the <I>checkPassword</I> function confirms that a user has entered a valid password. If the password is not valid, the select method highlights the password field and the focus method returns focus to 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><INPUT TYPE="password" NAME="userPass"></PRE>
<H3>相关</H3>
<LI><A HREF="ref_a-c.htm#blur_method" blur_method">blur</A>, <A HREF="ref_f-g.htm#focus_method" focus_method">focus</A> methods
<!------------------------------------------------------------------------------------------------>
<HR>
<A NAME="select_object"><H2>select object (<I>options</I> array)</H2></A>
<P>A selection list or scrolling list on an htm form. A selection list lets the user choose one item from a list. A scrolling list lets the user choose one or more items from a list.
<H3>语法</H3>
<P>To define a select object, use standard htm 语法 with the addition of the onBlur, onChange, and onFocus event handlers:
<PRE>
<SELECT
NAME="<I>selectName</I>"
[SIZE="<I>integer</I>"]
[MULTIPLE]
[onBlur="<I>handlerText</I>"]
[onChange="<I>handlerText</I>"]
[onFocus="<I>handlerText</I>"]>
<OPTION VALUE="<I>optionValue</I>" [SELECTED]> <I>textToDisplay</I> [ ... <OPTION> <I>textToDisplay</I>]
</SELECT>
</PRE>
<I>NAME="selectName"</I> specifies the name of the select object. You can access this value using the name property.
<BR><I>SIZE="integer"</I> specifies the number of options visible when the form is displayed.
<BR><I>MULTIPLE</I> specifies that the select object is a scrolling list (not a selection list).
<BR><I>OPTION</I> specifies a selection element in the list. You can access the options using the options array.
<BR><I>VALUE="optionValue"</I> specifies a value that is returned to the server when the option is selected and the form is submitted. You can access this value using the value property.
<BR><I>SELECTED</I> specifies that the option is selected by default. You can access this value using the defaultSelected property.
<BR><I>textToDisplay</I> specifies the text to display in the list. You can access this value using the text property.
<P>To use a select object's properties and methods:
<PRE>
1. <I>selectName</I>.<I>propertyName</I>
2. <I>selectName</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>selectName</I> is the value of the NAME attribute of a select 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 select 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.
<P>To use an option's properties:
<PRE>
1. <I>selectName</I>.options[<I>index1</I>].<I>propertyName</I>
2. <I>formName</I>.elements[<I>index2</I>].options[<I>index1</I>].<I>propertyName</I>
</PRE>
<I>selectName</I> is the value of the NAME attribute of a select object.
<BR><I>index1</I> is an integer representing an option in a select 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>index2</I> is an integer representing a select object on a form.
<BR><I>propertyName</I> is one of the properties listed below.
<H3>Property of</H3>
<LI>The select object is a property of <A HREF="ref_f-g.htm#form_object" form_object">form</A>
<LI>The options array is a property of <A HREF="ref_s-s.htm#select_object" select_object">select</A>
<H3>描述</H3>
<P>A select object on a form looks as follows. The object on the left is a selection list that lets the user choose one item; the object on the right is a scrolling list that lets the user choose one or more items:
<FORM>
<SELECT NAME="music_type_single">
<OPTION SELECTED> R&B
<OPTION> Jazz
<OPTION> Blues
<OPTION> New Age
</SELECT>
<SELECT NAME="music_type_multi" MULTIPLE>
<OPTION SELECTED> R&B
<OPTION> Jazz
<OPTION> Blues
<OPTION> New Age
</SELECT>
</FORM>
<P>A select object is a form element and must be defined within a <FORM> tag.
<H4>The <I>options</I> array</H4>
<P>You can reference the options of a select object in your code by using the <I>options</I> array. This array contains an entry for each option in a select object (<OPTION> tag) in source order. For example, if a select object named <I>musicStyle</I> contains three options, these options are reflected as <TT>musicStyle.options[0]</TT>, <TT>musicStyle.options[1]</TT>, and <TT>musicStyle.options[2]</TT>.
<P>To use the <I>options</I> array:
<PRE>
1. <I>selectName</I>.options
2. <I>selectName</I>.options[<I>index</I>]
3. <I>selectName</I>.options.length
</PRE>
<P><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>index</I> is an integer representing an option in a select object.
<P>To obtain the number of options in a select object, use the length property of either the options array or the select object:
<PRE>
1. <I>selectName</I>.length
2. <I>selectName</I>.options.length
</PRE>
<P>The select object has properties that you can access only through the options array. These properties are listed below.
<P>Even though each element in the <I>options</I> array represents a select option, the value of options[<I>index</I>] is always null. The value returned by <I>selectName</I>.options represents the full htm statement for the <I>selectName</I> object.
<P>Elements in the <I>options</I> array are read-only. For example, the statement <TT><I>selectName</I>.options[0]="guitar"</TT> has no effect.
<H3>Properties</H3>
<P>The select object has the following properties:
<LI><A HREF="ref_h-l.htm#length_property" length_property">length</A> reflects the number of options in a select object
<LI><A HREF="ref_m-q.htm#name_property" name_property">name</A> reflects the NAME attribute
<LI><A HREF="ref_s-s.htm#select_object" select_object">options</A> reflects the <OPTION> tags
<LI><A HREF="ref_s-s.htm#selectedIndex_property" selectedIndex_property">selectedIndex</A> reflects the index of the selected option (or the first selected option, if multiple options are selected)
<P>The <I>options</I> array has the following properties:
<LI><A HREF="ref_d-e.htm#defaultSelected_property" defaultSelected_property">defaultSelected</A> reflects the SELECTED attribute
<LI><A HREF="ref_h-l.htm#index_property" index_property">index</A> reflects the index of an option
<LI><A HREF="ref_h-l.htm#length_property" length_property">length</A> reflects the number of options in a select object
<LI><A HREF="ref_m-q.htm#name_property" name_property">name</A> reflects the NAME attribute
<LI><A HREF="ref_s-s.htm#selected_property" selected_property">selected</A> lets you programatically select an option
<LI><A HREF="ref_s-s.htm#selectedIndex_property" selectedIndex_property">selectedIndex</A> reflects the index of the selected option
<LI><A HREF="ref_t-z.htm#text_property" text_property">text</A> reflects the <I>textToDisplay</I> that follows an <OPTION> tag
<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#blur_method" blur_method">blur</A>
<LI><A HREF="ref_f-g.htm#focus_method" focus_method">focus</A>
<H3>Event handlers</H3>
<LI><A HREF="ref_m-q.htm#onBlur_event" onBlur_event">onBlur</A>
<LI><A HREF="ref_m-q.htm#onChange_event" onChange_event">onChange</A>
<LI><A HREF="ref_m-q.htm#onFocus_event" onFocus_event">onFocus</A>
<H3>例子</H3>
<P><B>Example 1.</B> The following example displays a selection list and a scrolling list.
<XMP>
Choose the music type for your free CD:
<SELECT NAME="music_type_single">
<OPTION SELECTED> R&B
<OPTION> Jazz
<OPTION> Blues
<OPTION> New Age
</SELECT>
<P>Choose the music types for your free CDs:
<BR><SELECT NAME="music_type_multi" MULTIPLE>
<OPTION SELECTED> R&B
<OPTION> Jazz
<OPTION> Blues
<OPTION> New Age
</SELECT>
</XMP>
<P><B>Example 2.</B> The following example displays two selection lists that let the user choose a month and day. These selection lists are initialized to the current date. The user can change the month and day by using the selection lists or by choosing preset dates from radio buttons. Text fields on the form display the values of the select object's properties and indicate the date chosen and whether it is Cinco de Mayo.
<XMP>
<htm>
<HEAD>
<TITLE>Select object example</TITLE>
</HEAD>
<BODY>
<SCRIPT>
var today = new Date()
//---------------
function updatePropertyDisplay(monthObj,dayObj) {
// Get date strings
var monthInteger, dayInteger, monthString, dayString
monthInteger=monthObj.selectedIndex
dayInteger=dayObj.selectedIndex
monthString=monthObj.options[monthInteger].text
dayString=dayObj.options[dayInteger].text
// Display property values
document.selectForm.textFullDate.value=monthString + " " + dayString
document.selectForm.textMonthLength.value=monthObj.length
document.selectForm.textDayLength.value=dayObj.length
document.selectForm.textMonthName.value=monthObj.name
document.selectForm.textDayName.value=dayObj.name
document.selectForm.textMonthIndex.value=monthObj.selectedIndex
document.selectForm.textDayIndex.value=dayObj.selectedIndex
// Is it Cinco de Mayo?
if (monthObj.options[4].selected && dayObj.options[4].selected)
document.selectForm.textCinco.value="Yes!"
else
document.selectForm.textCinco.value="No"
}
</SCRIPT>
<!--------------->
<FORM NAME="selectForm">
<P><B>Choose a month and day:</B>
Month: <SELECT NAME="monthSelection"
onChange="updatePropertyDisplay(this,document.selectForm.daySelection)">
<OPTION> January <OPTION> February <OPTION> March
<OPTION> April <OPTION> May <OPTION> June
<OPTION> July <OPTION> August <OPTION> September
<OPTION> October <OPTION> November <OPTION> December
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -