/*
* 用于去掉输入本框内容中的空格
* @author 巩玲玲
* */
$("input[type='text'],input[type='password']").bind("change blur",function(){
var res = "", c;
for ( var i = 0; i < $(this).val().length; i++) {
c = $(this).val().charCodeAt(i);
if (c==32)// 65281 65374
{
}
else
res+=String.fromCharCode(c);
}
$(this).val(res);
});
* 用于去掉输入本框内容中的空格
* @author 巩玲玲
* */
$("input[type='text'],input[type='password']").bind("change blur",function(){
var res = "", c;
for ( var i = 0; i < $(this).val().length; i++) {
c = $(this).val().charCodeAt(i);
if (c==32)// 65281 65374
{
}
else
res+=String.fromCharCode(c);
}
$(this).val(res);
});
本文介绍了一个JavaScript脚本,该脚本能自动移除HTML中输入框(text和password类型)内的空白字符,包括全角和半角空格。通过监听change和blur事件实现,确保用户输入的数据不包含空白字符。

被折叠的 条评论
为什么被折叠?



