当前页面: 开发资料首页 → Javascript 专题 → javascript手冊-i
摘要: javascript
An integer representing the index of an option in a select object.
selectName.options[indexValue].index
selectName is either the value of the NAME attribute of a select object or an element in the elements array.
indexValue is an integer representing an option in a select object.
options array
The number identifying the position of the option in the selection, starting from zero.
Returns the index within the calling string object of the first occurrence of the specified value, starting the search at fromIndex.
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.
string
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.
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 6 document.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"))
On Unix platforms, evaluates an argument to determine if it is "NaN" (not a number).
isNaN(testValue)
testValue is the value you want to evaluate.
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 "NaN".
The isNaN function returns true or false.
The following example evaluates floatValue to determine if it is a number, then calls a procedure accordingly.
floatValue=parseFloat(toFloat) if isNaN(floatValue) { notFloat() } else { isFloat() }
Causes a string to be italicized as if it were in an tag.
语法
stringName.italics()
stringName is any string or a property of an existing object.
string
Use the italics method with the write or writeln methods to format and display a string in a document.
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