1
<p id="demo">单击按钮显示截取部分.</p>
2
<button onclick="myFunction()">点我</button>
3
<script>
4
function myFunction() {
5
var str = "Hello world!";
6
var n = str.slice(0, 1);
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.slice(0, 1);
document.getElementById("demo").innerHTML = n;
}
</script>