欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JavaScript indexOf() 方法

定義和用法

indexOf() 方法可返回某個指定的字符串值在字符串中首次出現(xiàn)的位置。

語法

stringObject.indexOf(searchvalue,fromindex)
參數(shù) 描述
searchvalue 必需。規(guī)定需檢索的字符串值。
fromindex 可選的整數(shù)參數(shù)。規(guī)定在字符串中開始檢索的位置。它的合法取值是 0 到 stringObject.length - 1。如省略該參數(shù),則將從字符串的首字符開始檢索。

說明

該方法將從頭到尾地檢索字符串 stringObject,看它是否含有子串 searchvalue。開始檢索的位置在字符串的 fromindex 處或字符串的開頭(沒有指定 fromindex 時)。如果找到一個 searchvalue,則返回 searchvalue 的第一次出現(xiàn)的位置。stringObject 中的字符位置是從 0 開始的。

提示和注釋

注釋:indexOf() 方法對大小寫敏感!

注釋:如果要檢索的字符串值沒有出現(xiàn),則該方法返回 -1。

實例

在本例中,我們將在 "Hello world!" 字符串內(nèi)進行不同的檢索:

<script type="text/javascript">

var str="Hello world!"
document.write(str.indexOf("Hello") + "<br />")
document.write(str.indexOf("World") + "<br />")
document.write(str.indexOf("world"))

</script>

以上代碼的輸出:

0
-1
6

TIY

indexOf()
如何使用 indexOf() 在字符串內(nèi)進行檢索。

參閱

charCodeAt() 方法、lastIndexOf() 方法、substring() 方法