JavaScript Handbook -i

zhaozj2021-02-17  55

Index Property

An Integer Repensenting The Index of An Option In A SELECT OBJECT.

grammar

Selectname.Options [IndexValue] .index

..............................

Property of

Options array

description

The number identifying the position of the option in the selection, starting from zero.

Relevant

DefaultSelected, SELECTED, SELECTEDIDEX Properties

indexOf method Returns the index within the calling string object of the first occurrence of the specified value, starting the search at fromIndex. Syntax stringName.indexOf (searchValue, [fromIndex]) stringName is any string or a property of an existing object. searchValue is a string or a property of an existing object, representing the value to search for fromIndex is the location within the calling string to start the search from It can be any integer from 0 to stringName.length -.. 1 or a property of an existing . object Method of string described 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 stringName.length -. 1. If you do not specify a value for fromIndex, JavaScript assumes 0 by default. If searchValue is not found, JavaScript returns -1. examples The following example uses indexOf and lastIndexOf to locate values ​​in the string "Brave new world". var anyString = "Brave new world"

// Displays 8

Document.write ("

the index of the first w from the beginning is"

Anystring.indexof ("W"))

// displays 10

Document.write ("

the index of the first w from the end is"

Anystring.lastIndexof ("W")))

// Displays 6Document.write ("

the index of 'new' from the beginning is"

Anystring.indexof ("new")))

// Displays 6

Document.write ("

the index of 'new' from the end is"

Anystring.lastIndexof ("new")))

Related Charat, LastIndexof Methods

isNaN function On Unix platforms, evaluates an argument to determine if it is "NaN" (not a number). Syntax isNaN (testValue) testValue is the value you want to evaluate. Description The isNaN function is a built-in JavaScript function. It is not a method associated with any object, but is part of the language itself. isNaN is available on Unix platforms only. On all platforms except Windows, the parseFloat and parseInt functions return "NaN" when they evaluate a value that is not a number . The "NaN" value is not a number in any radix. You can call the isNaN function to determine if the result of parseFloat or parseInt is "NaN". If "NaN" is passed on to arithmetic operations, the operation results will also BE ISNAN FUNCTION RETURns TRUE OR FALSE. Example The Following Example Evaluates FloatValue To Determine IT ITVALUE = PARSEFLOAT (TOFLOAT)

IF isnan (floatvalue) {

NOTFLOAT ()

} else {

isfloat ()

}

Parsefloat, Parseint Functions

italics method Causes a string to be italicized as if it were in an tag. Syntax stringName.italics () stringName is any string or a property of an existing object. Method of string Description Use the italics method with the write or writeln . methods to format and display a string in a document examples The following example uses string methods to change the formatting of a string: var worldString = "Hello, world" document.write (worldString.blink ())

Document.write ("

" worldString.bold ())

Document.write ("

" worldString.italics ())

Document.write ("

" worldString.strike ())

The Previous Example Produces The Same Output As The Following HTM: Hello, World

Hello, World

Hello, World

Hello, World

Related Blink, Bold, Strike Methods

转载请注明原文地址:https://www.9cbs.com/read-30716.html

New Post(0)