WEB开发网
开发学院网页设计JavaScript Select object example 阅读

Select object example

 2007-11-27 17:50:45 来源:WEB开发网   
核心提示: search propertyA string beginning with a question mark that specifies any query information in the URL. 语法1. links[index].search2. location.searchindex is an i
 

search property

A string beginning with a question mark that specifies any query information in the URL.

语法

1. links[index].search2. location.search

index is an integer representing a link object.

Property of

link, location

描述

The search property specifies a portion of the URL.

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.

See Section 3.3 of RFC 1738 for complete information about the search.

例子

In the following example, the window.open statement creates a window called newWindow and loads the specified URL into it. The document.write statements display all the properties of newWindow.location in a window called msgWindow.

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()

The previous example displays the following output:

newWindow.location.href =   http://guide-p.infoseek.com/WW/NS/Titles?qt=RFC+1738+&col=WWnewWindow.location.protocol = http:newWindow.location.host = guide-p.infoseek.comnewWindow.location.hostName = guide-p.infoseek.comnewWindow.location.port = newWindow.location.pathname = /WW/NS/TitlesnewWindow.location.search = ?qt=RFC+1738+&col=WWnewWindow.location.hash = 

相关

  • hash, host, hostname, href, pathname, port, protocol properties

    select method

    Selects the input area of the specified password, text, or textarea object.

    语法

    1. passwordName.select()2. textName.select()3. textareaName.select()

    passwordName is either the value of the NAME attribute of a password object or an element in the elements array.
    textName is either the value of the NAME attribute of a text object or an element in the elements array.
    textareaName is either the value of the NAME attribute of a textarea object or an element in the elements array.

    方法

    password, text, textarea

    描述

    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.

    例子

    In the following example, the checkPassword 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.

    function checkPassword(userPass) {   if (badPassword) {      alert(Please enter your password again.)      userPass.focus()      userPass.select()   }}
    This example assumes that the password is defined as:
    <INPUT TYPE=password NAME=userPass>

    相关

  • blur, focus methods

    select object (options array)

    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.

    语法

    To define a select object, use standard htm 语法 with the addition of the onBlur, onChange, and onFocus event handlers:

    <SELECT   NAME=selectName   [SIZE=integer]   [MULTIPLE]   [onBlur=handlerText]   [onChange=handlerText]   [onFocus=handlerText]>   <OPTION VALUE=optionValue [SELECTED]> textToDisplay [ ... <OPTION> textToDisplay]</SELECT>
    NAME=selectName specifies the name of the select object. You can access this value using the name property.
    SIZE=integer specifies the number of options visible when the form is displayed.
    MULTIPLE specifies that the select object is a scrolling list (not a selection list).
    OPTION specifies a selection element in the list. You can access the options using the options array.
    VALUE=optionValue 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.
    SELECTED specifies that the option is selected by default. You can access this value using the defaultSelected property.
    textToDisplay specifies the text to display in the list. You can access this value using the text property.

    To use a select objects properties and methods:

    1. selectName.propertyName2. selectName.methodName(parameters)3. formName.elements[index].propertyName4. formName.elements[index].methodName(parameters)
    selectName is the value of the NAME attribute of a select object.
    formName is either the value of the NAME attribute of a form object or an element in the forms array.
    index is an integer representing a select object on a form.
    propertyName is one of the properties listed below.
    methodName is one of the methods listed below.

    To use an options properties:

    1. selectName.options[index1].propertyName2. formName.elements[index2].options[index1].propertyName
    selectName is the value of the NAME attribute of a select object.
    index1 is an integer representing an option in a select object.
    formName is either the value of the NAME attribute of a form object or an element in the forms array.
    index2 is an integer representing a select object on a form.
    propertyName is one of the properties listed below.

    Property of

  • The select object is a property of form
  • The options array is a property of select

    描述

    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:

    A select object is a form element and must be defined within a <FORM> tag.

    The options array

    You can reference the options of a select object in your code by using the options 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 musicStyle contains three options, these options are reflected as musicStyle.options[0], musicStyle.options[1], and musicStyle.options[2].

    To use the options array:

    1. selectName.options2. selectName.options[index]3. selectName.options.length

    selectName is either the value of the NAME attribute of a select object or an element in the elements array.
    index is an integer representing an option in a select object.

    To obtain the number of options in a select object, use the length property of either the options array or the select object:

    1. selectName.length2. selectName.options.length

    The select object has properties that you can access only through the options array. These properties are listed below.

    Even though each element in the options array represents a select option, the value of options[index] is always null. The value returned by selectName.options represents the full htm statement for the selectName object.

    Elements in the options array are read-only. For example, the statement selectName.options[0]=guitar has no effect.

    Properties

    The select object has the following properties:

  • length reflects the number of options in a select object
  • name reflects the NAME attribute
  • options reflects the <OPTION> tags
  • selectedIndex reflects the index of the selected option (or the first selected option, if multiple options are selected)

    The options array has the following properties:

  • defaultSelected reflects the SELECTED attribute
  • index reflects the index of an option
  • length reflects the number of options in a select object
  • name reflects the NAME attribute
  • selected lets you programatically select an option
  • selectedIndex reflects the index of the selected option
  • text reflects the textToDisplay that follows an <OPTION> tag
  • value reflects the VALUE attribute

    Methods

  • blur
  • focus

    Event handlers

  • onBlur
  • onChange
  • onFocus

    例子

    Example 1. The following example displays a selection list and a scrolling list.

    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>

    Example 2. 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 objects properties and indicate the date chosen and whether it is Cinco de Mayo.

    <htm><HEAD><TITLE>Select object example</TITLE></HEAD><body><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</SELECT>Day: <SELECT NAME=daySelection onChange=updatePropertyDisplay(document.selectForm.monthSelection,this)> <OPTION> 1 <OPTION> 2 <OPTION> 3 <OPTION> 4 <OPTION> 5 <OPTION> 6 <OPTION> 7 <OPTION> 8 <OPTION> 9 <OPTION> 10 <OPTION> 11 <OPTION> 12 <OPTION> 13 <OPTION> 14 <OPTION> 15 <OPTION> 16 <OPTION> 17 <OPTION> 18 <OPTION> 19 <OPTION> 20 <OPTION> 21 <OPTION> 22 <OPTION> 23 <OPTION> 24 <OPTION> 25 <OPTION> 26 <OPTION> 27 <OPTION> 28 <OPTION> 29 <OPTION> 30 <OPTION> 31</SELECT><p><B>Set the date to: </B><INPUT TYPE=radio NAME=dateChoice onClick= monthSelection.selectedIndex=0; daySelection.selectedIndex=0; updatePropertyDisplay(document.selectForm.monthSelection,document.selectForm.daySelection)> New Years Day<INPUT TYPE=radio NAME=dateChoice onClick= monthSelection.selectedIndex=4; daySelection.selectedIndex=4; updatePropertyDisplay(document.selectForm.monthSelection,document.selectForm.daySelection)> Cinco de Mayo<INPUT TYPE=radio NAME=dateChoice onClick= monthSelection.selectedIndex=5; daySelection.selectedIndex=20; updatePropertyDisplay(document.selectForm.monthSelection,document.selectForm.daySelection)> Summer Solstice<p><B>Property values:</B><br/>Date chosen: <INPUT TYPE=text NAME=textFullDate VALUE= SIZE=20><br/>monthSelection.length<INPUT TYPE=text NAME=textMonthLength VALUE= SIZE=20><br/>daySelection.length<INPUT TYPE=text NAME=textDayLength VALUE= SIZE=20><br/>monthSelection.name<INPUT TYPE=text NAME=textMonthName VALUE= SIZE=20><br/>daySelection.name<INPUT TYPE=text NAME=textDayName VALUE= SIZE=20><br/>monthSelection.selectedIndex<INPUT TYPE=text NAME=textMonthIndex VALUE= SIZE=20><br/>daySelection.selectedIndex<INPUT TYPE=text NAME=textDayIndex VALUE= SIZE=20><br/>Is it Cinco de Mayo? <INPUT TYPE=text NAME=textCinco VALUE= SIZE=20></FORM></BODY></htm>

    相关 the 例子 for the defaultSelected property.

    相关

  • form and radio objects

    selected property

    A Boolean value specifying the current selection state of an option in a select object.

    语法

    selectName.options[index].selected

    selectName is either the value of the NAME attribute of a select object or an element in the elements array.
    index is an integer representing an option in a select object.

    Property of

    options array

    描述

    If an option in a select object is selected, the value of its selected property is true; other

  • Tags:Select object example

    编辑录入:coldstar [复制链接] [打 印]
    赞助商链接