var reg = /\s*/g;
$('.modal-content').find('input').focusout(function () {
if ($(this).val() == '' || reg.test($(this).value)) {
$(this).css('backgroundColor','#FFEFEF');
$(this).nextAll('.hintWrap').css('display','block');
console.log(reg.test($(this).value));
} else {
$(this).css('backgroundColor','#F5F5F5');
$(this).nextAll('.hintWrap').css('display','none');
console.log(reg.test($(this).value));
}
})
谢谢!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
/s*/g能匹配成功任意字符,(包括空串。个数随意,没有也行).因为所有的都能包含""。
评论区转码了,写这了
楼主,你这正则有问题哦,我看了一下控制台,它是一直进入if项的,也就是说,因为你正则的问题,你这个方法一直是执行的if内的语句:var reg =/s+/;你把正则改成这样试试