我有以下代码片段工作正常:
$(function(){
//trim all input-text fields and remove extra spaces
$('body').on('blur',':text',function(){
var newVal=$(this).val().trim();
$(this).val( newVal.replace( /\s+/g, ' ' ) );
});
});
问题是我还需要选择搜索输入字段,我尝试了以下但没有成功:
':text,:search'
感谢所有帮助。
最佳答案
没有:search
这样的选择器,所以可以使用属性选择器 [type=search]
而不是
$(function(){
//trim all input-text fields and remove extra spaces
$('body').on('blur','[type=search],:text',function(){
var newVal=$(this).val().trim();
$(this).val( newVal.replace( /\s+/g, ' ' ) );
});
});
关于javascript - 如何选择输入类型文本并在 jQuery 中搜索 body 模糊?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31947957/