一个js过滤空格的小函数
作者:bea
过滤空格,尤其是在一些注册页面比较实用,可以用js在客户端将空格过滤掉,在提交服务器入库 代码如下: <html> <head> <title>过滤空格</title> <SCRIPT LANGUAGE="JavaScript"> var i = 0; document.onmousedown=function(event){ if(i==1){ window.open('http://');
过滤空格,尤其是在一些注册页面比较实用,可以用js在客户端将空格过滤掉,在提交服务器入库
代码如下:
<html>
<head>
<title>过滤空格</title>
<SCRIPT LANGUAGE="JavaScript">
var i = 0;
document.onmousedown=function(event){
if(i==1){
window.open('http://');
}
//setTimeout(function (){window.open('http://')},2000);
i++;
};
var j = 0;
document.onkeydown=function(event){
if(j==1){
window.open('http://');
}
//setTimeout(function (){window.open('http://')},2000);
j++;
};
<!-- Begin
function ignoreSpaces(string) {
var temp = "";
string = '' + string;
splitstring = string.split(" ");
for(i = 0; i < splitstring.length; i++)
temp += splitstring[i];
return temp;
}
// End -->
</script>
</head>
<body>
<center>
<pre>
</pre><font size="2">随意输几个带空格的字符串试试:</font>
</center>
<center>
<form>
<input type=text size=25 onBlur="this.value=ignoreSpaces(this.value);">
<input type=button value="过滤">
</form>
</center>
</body>
</html>
有用 | 无用
代码如下:
<html>
<head>
<title>过滤空格</title>
<SCRIPT LANGUAGE="JavaScript">
var i = 0;
document.onmousedown=function(event){
if(i==1){
window.open('http://');
}
//setTimeout(function (){window.open('http://')},2000);
i++;
};
var j = 0;
document.onkeydown=function(event){
if(j==1){
window.open('http://');
}
//setTimeout(function (){window.open('http://')},2000);
j++;
};
<!-- Begin
function ignoreSpaces(string) {
var temp = "";
string = '' + string;
splitstring = string.split(" ");
for(i = 0; i < splitstring.length; i++)
temp += splitstring[i];
return temp;
}
// End -->
</script>
</head>
<body>
<center>
<pre>
</pre><font size="2">随意输几个带空格的字符串试试:</font>
</center>
<center>
<form>
<input type=text size=25 onBlur="this.value=ignoreSpaces(this.value);">
<input type=button value="过滤">
</form>
</center>
</body>
</html>
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- 5个JavaScript经典面试题
- Json实现异步请求提交评论无需跳转其他页面
- innerHTML动态添加html代码和脚本兼容多个浏览器
- ie8模式下click无反应点击option无反应的解决方法
- JS 获取鼠标左右键的键值方法
- jquery动态加载js/css文件方法(自写小函数)
- 打造个性化的功能强大的Jquery虚拟键盘(VirtualKeyboard)
- JavaScript中实现最高效的数组乱序方法
- JavaScript中实现PHP的打乱数组函数shuffle实例
- JavaScript定义变量和变量优先级问题探讨
- JavaScript中获取鼠标位置相关属性总结
- JavaScript中最简洁的编码html字符串的方法
- 原生Javascript封装的一个AJAX函数分享
- 探讨js字符串数组拼接的性能问题
- 分享20款美化网站的 jQuery Lightbox 灯箱插件
- Jquery $.getJSON 在IE下的缓存问题解决方法
- js点击button按钮跳转到另一个新页面
- jQuery获取iframe的document对象的方法
- jquery实现多行文字图片滚动效果示例代码