1
<p id="demo">点击按钮截取字符串。</p>
2
<button onclick="myFunction()">点我</button>
3
<script>
4
function myFunction() {
5
var str = "Hello world!";
6
var n = str.substr(2, 3);
7
document.getElementById("demo").innerHTML = n;
8
}
9
</script>
<p id="demo">点击按钮截取字符串。</p>
<button onclick="myFunction()">点我</button>
<script>
function myFunction() {
var str = "Hello world!";
var n = str.substr(2, 3);
document.getElementById("demo").innerHTML = n;
}
</script>