在你要输入数字的标签上加上这个属性:
onkeyup='this.value=this.value.replace(/\D/gi,""),就可以了。
var spanContent = '请输入数字'
var contentBox = document.querySelector('.weui_textarea')
contentBox.onfocus = function() {
if (contentBox.innerHTML === spanContent) {
contentBox.innerHTML = '';
}
}
contentBox.onblur = function() {
if (contentBox.innerHTML === '') {
contentBox.innerHTML = spanContent;
}
}
contentBox.oninput = function(event) {
var newData = event.data;
if(/\d/.test(Number(newData))) {
console.log('是数字');
} else {
console.log('不是数字');
contentBox.innerHTML = contentBox.innerHTML.replace(newData, '');
}
}