<html>
<head>
<title>substring()和slice()</title>
<script language="javascript">
var myStr = "Tsinghua university";
document.write(myStr.substring(1,3) + "<br/>");
document.write(myStr.slice(1,3) + "<br/>");
document.write(myStr.slice(4) + "<br/>");
document.write(myStr+ "<br/>");//不改变
</script>
</head>
</html>
以上代码输出结果:
si
si
ghua university
Tsinghua university