indexOf 方法
返回 String 对象内第一次出现子字符串的字符位置。 strObj.indexOf(subString[, startIndex])参数
strObj必选项。String 对象或文字。subString必选项。要在 String 对象中查找的子字符串。starIndex可选项。该整数值指出在 String 对象内开始查找的索引。如果省略,则从字符串的开始处查找。说明
indexOf 方法返回一个整数值,指出 String 对象内子字符串的开始位置。如果没有找到子字符串,则返回 -1。 如果 startindex 是负数,则 startindex 被当作零。如果它比最大的字符位置索引还大,则它被当作最大的可能索引。 从左向右执行查找。否则,该方法与 lastIndexOf 相同。示例
下面的示例说明了 indexOf 方法的用法。function IndexDemo(str2){
var str1 = "BABEBIBOBUBABEBIBOBU"
var s = str1.indexOf(str2);
return(s);
}
返回 String 对象内第一次出现子字符串的字符位置。 strObj.indexOf(subString[, startIndex])参数
strObj必选项。String 对象或文字。subString必选项。要在 String 对象中查找的子字符串。starIndex可选项。该整数值指出在 String 对象内开始查找的索引。如果省略,则从字符串的开始处查找。说明
indexOf 方法返回一个整数值,指出 String 对象内子字符串的开始位置。如果没有找到子字符串,则返回 -1。 如果 startindex 是负数,则 startindex 被当作零。如果它比最大的字符位置索引还大,则它被当作最大的可能索引。 从左向右执行查找。否则,该方法与 lastIndexOf 相同。示例
下面的示例说明了 indexOf 方法的用法。function IndexDemo(str2){
var str1 = "BABEBIBOBUBABEBIBOBU"
var s = str1.indexOf(str2);
return(s);
}
解决方案 »
- jquery的 $.ajax 方法一直ERROR~
- try不到exception。
- 关于javascript实现复选框全选问题
- 谁可以教我下要如何做个‘选项卡’啊?
- js 颜色比较
- 请大家推荐一本javascript书
- 请教:用鼠标移动TEXT,如何保持鼠标和TEXT控件的相对位置?
- meizz(梅花雨) 我载下来了,可是跟我原来那个一模一样。http://www.lostinet.com/download/reference/HTMLREF.CHM
- 用jquery如何实现动态创建EasyUi datagrid列?代码如下:
- 下面这个幻灯片脚本如何改成能播放5张图片?
- 写一个js脚本,检查checkbox中是否已经有选中的,没选则弹出对话框,在等待。。。。。
- ModalDialog刷新父页面
Returns the character position where the first occurrence of a substring occurs within a String object. strObj.indexOf(subString[, startIndex])Arguments
strObjRequired. A String object or literal.subStringRequired. Substring to search for within the String object.startIndexOptional. Integer value specifying the index to begin searching within the String object. If omitted, searching starts at the beginning of the string.Res
The indexOf method returns an integer value indicating the beginning of the substring within the String object. If the substring is not found, a -1 is returned. If startindex is negative, startindex is treated as zero. If it is larger than the greatest character position index, it is treated as the largest possible index. Searching is performed from left to right. Otherwise, this method is identical to lastIndexOf.Example
The following example illustrates the use of the indexOf method.function IndexDemo(str2){
var str1 = "BABEBIBOBUBABEBIBOBU"
var s = str1.indexOf(str2);
return(s);
}
if request.form("result")=100 then
str1="1982ewqu"
str2="e"
xxx=Instr(str1,str2)
response.write xxx
end if
%>
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
<script language="javascript">
function testdata()
{
var str1="1982ewqu";
var str2="e";
alert(str1.indexOf(str2));
}
</script></head>
<body onload="testdata();">
<form method="POST" action="" name="DFrm" id="DFrm">
<input type="text" name="bh" id="bh" size="13" class="input">
<input type="hidden" name="result" value=100>
<input type="button" value="查看" onclick="DFrm.submit();">
</form>
<p>javascript:indexOf()返回 String 对象内第一次出现子字符串的字符位置。它与vbscript中的Instr()的作用相当</p> <p>vbscript:返回搜寻字符串的第一个位置</p></body></html>
if (tt.indexOf(".")!=-1)
{
alert("yes!")
alert(tt.indexOf("."));
}