华强北专业苹果维修:帮我看下这段代码,运行出现错误

来源:百度文库 编辑:查人人中国名人网 时间:2024/05/05 20:20:52
<html>
<script language=javascript>
function testChar(str)
{
Var l,pos;
l=str.length;
pos=str.CharAt(l-1);
alert(l);
alert(pos);
}
</script>
<body>
<form name=frm1>
<input type=button onclick="testChar('Hello');" value="clickme">
</form>
</body>
</html>

javacript是有区分大小写的,这一点请楼主注意

以上代码中两个错误
变量声明:var
字符索引:charAt

请注意大小写!!

function testChar(str)
修改为:
function testChar(Hello)

<input type=button onclick="testChar('Hello');" value="clickme">
修改为:
<input type=button onclick="testChar('str');" value="clickme">

Var 应该为 var
CharAt应该为charAt()
javascript的函数是区分大小写的!

程序没有错啊
你换一台机看看

str未定义!