练习要求
编写页面,页面中有一个输入框,一个按钮
要求,在点击按钮的时候,控制台输出前20个字符的字符串
报错源码
<input type="text" id="text4">
<button id="btn2">点击我</button>
window.alert("请输入语句2");
var text4 =document.getElementById(‘text4‘);
var btn2 =document.getElementById(‘btn2‘);
//点击后操作
btn2.onclick =function (){
console.log(text4.value.silent(0,20));//报错Uncaught TypeError: text4.value.silent is not a function
at HTMLButtonElement.btn2.onclick
};
btn2.onclick =function (){
console.log(text4.value.slice(0,20));//silent改为了slice
};
silce( )
方法silce()
方法怎么使用原文:https://www.cnblogs.com/pandudu/p/14894860.html