xxxxxxxxxx
<!DOCTYPE html>
<html>
<title>JavaScript substr() 方法字符串提取示例 - 基础教程(div.cn)</title>
<body>
<h1>JavaScript substr() 方法</h1>
<p>单击按钮以从位置4提取字符串的一部分,长度为18:</p>
<button onclick="myFunc()">Click</button>
<p id="x"></p>
<script>
function myFunc() {
var str1 = 'Air Pollution is introduction of chemicals to the atmosphere.';
var str2 = str1.substr(4, 18);
document.getElementById('x').innerHTML = str2;
}
</script>
</body>
</html>