<html>
<body>
<p>单击该按钮以显示提取的字符串部分。</p>
<button onclick="myFunction()">试一试</button>
<p id="demo"></p>
<p><strong>注意:</strong> IE 11(及更早版本)不支持 repeat() 方法。</p>
<script>
function myFunction() {
var str = "Hello world!";
document.getElementById("demo").innerHTML = str.repeat(2);
}
</script>
</body>
</html>