首页
IT
登录
6mi
u
盘
搜
搜 索
IT
JavaScript 字符串案例 indexOf lastIndexOf
JavaScript 字符串案例 indexOf lastIndexOf
xiaoxiao
2021-03-25
154
<!DOCTYPE html>
<
html
lang
=
"en"
>
<
head
>
<
meta
charset
=
"UTF-8"
>
<
title
>
</
title
>
</
head
>
<
body
>
字符串:
<
input
type
=
"text"
id
=
"txt"
>
索引字符串:
<
input
type
=
"text"
id
=
"index"
>
<
button
id
=
"btn"
>
从前面开始索引
</
button
>
<
button
id
=
"btn1"
>
从后面开始索引
</
button
>
</
body
>
</
html
>
<
script
>
function
$
(id)
{
return
document.getElementById(id);} $(
"btn"
).onclick =
function
()
{
alert($(
"txt"
).value.indexOf($(
"index"
).value) ); } $(
"btn1"
).onclick =
function
()
{
alert($(
"txt"
).value.lastIndexOf($(
"index"
).value) ); }
</
script
>
运行如下
转载请注明原文地址: https://ju.6miu.com/read-7315.html
技术
最新回复
(
0
)