indexof() 马上结

yyllgf 2003-10-10 08:30:16
indexof() 这个什么作用,怎么用,能否举个例子
...全文
39 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
no820824 2003-10-10
  • 打赏
  • 举报
回复
<script language=javascript>

var tt="23523546346";
if (tt.indexOf(".")!=-1)
{
alert("yes!")
alert(tt.indexOf("."));
}
scycgjr 2003-10-10
  • 打赏
  • 举报
回复
<%
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>
kingdomzhf 2003-10-10
  • 打赏
  • 举报
回复
indexOf Method
Returns the character position where the first occurrence of a substring occurs within a String object.

strObj.indexOf(subString[, startIndex])

Arguments
strObj

Required. A String object or literal.

subString

Required. Substring to search for within the String object.

startIndex

Optional. Integer value specifying the index to begin searching within the String object. If omitted, searching starts at the beginning of the string.

Remarks
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);
}
zhaoweiwei 2003-10-10
  • 打赏
  • 举报
回复
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);
}
longshenwang 2003-10-10
  • 打赏
  • 举报
回复
indexOf()的用法是判断一个字符串中是否有给定的特殊字符

具体用法是: 字符串 str 需要判断的字符

87,923

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧