<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>W3Cschool教程(w3cschool.cn)</title>
</head>
<body>
<p id="demo">单击按钮显示截取部分</p>
<button onclick="myFunction()">点我</button>
<script>
function myFunction(){
var str="Hello world!";
var n=str.slice(3,8);
document.getElementById("demo").innerHTML=n;
}
</script>
</body>
</html>