为什么String.replace()不能处理事件?
var el = document.querySelector('input')
var pat = /(\d{3})(\d{3})(\d{4})/;
el.oninput = function(){
this.value.replace(pat, '$1-$2-$3')
}
答案 0 :(得分:1)
好的,你没有指定或返回,因为你需要设置新值:
var el = document.querySelector('input')
var pat = /(\d{3})(\d{3})(\d{4})/;
el.oninput = function(){
this.value = this.value.replace(pat, '$1-$2-$3')
}