input标签获取焦点时文本框内提示信息清空(2)

逍遥老鬼 撰写  

  昨天,我发了一个input标签清空的日志,冰雪黑鹰说我的那个还不是很标准的,帮我重写了一个,现在的看着也简洁,而且也符合哪些什么标准,特别在这里感谢下。附上代码,以备后用……

js部分:

function addLoadEvent(func){
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
		window.onload = func;
	}else{
		window.onload = function(){
			oldonload();
			func();
		}
	}
}
 
function checkText(){
	var textId = document.getElementById('test');
	var textDefault = '请输入字符';
	function cls(){
		if (this.value == textDefault){
			this.value = '';
		}
	}
	function res(){
		if (this.value == ''){
			this.value = textDefault;
		}
	}
	textId.onfocus = cls;
	textId.onblur = res;
}
addLoadEvent (checkText);

html部分:

<input type="text" value="请输入字符" id="test" />

9 条评论

  1. 发表了 2009/01/08 在 8:41 上午 | 永久链接 | Reply

    好精致的代码,老鬼很有专研精神,谢谢

  2. 发表了 2009/01/08 在 8:50 上午 | 永久链接 | Reply

    我也不懂,请别人写的。

  3. 发表了 2009/01/08 在 10:41 上午 | 永久链接 | Reply

    oladonload(); <– 應該是 oldonload(); 吧

  4. 发表了 2009/01/08 在 10:53 上午 | 永久链接 | Reply

    恩,他那里是写错了,我现在去修改下。

  5. 发表了 2009/01/08 在 4:43 下午 | 永久链接 | Reply

    哈哈,也是个老博了啊,本来想申请链接来着,一看你的link页面,先给咱来了个下马威….晕倒

  6. 发表了 2009/01/08 在 6:34 下午 | 永久链接 | Reply

    不是不做,是要懂得筛选了,不要像当年傻乎乎的什么链接都做了,过个三天五天的,一半打不开了,要知道,那时候实在太郁闷了。还有就是做链接时候挺好一网站,过几天再去看,完了,成垃圾站了。最可恶的是,有变化,都不通知的。

  7. SNAKE
    发表了 2009/01/12 在 9:29 上午 | 永久链接 | Reply

    这个不错~~我以前写过一个,远不如这个写的好~~还需要多多学习啊!

  8. 发表了 2009/01/12 在 9:55 上午 | 永久链接 | Reply

    写的好就收藏吧。

  9. 发表了 2009/01/18 在 9:26 上午 | 永久链接 | Reply

    很牛,都挺厉害的.

发表评论

Your email is never shared. 标记为 * 的为必填项目

*
*