读书人

给form表单元素平添提示tooltip

发布时间: 2012-08-21 13:00:21 作者: rapoo

给form表单元素添加提示tooltip
<input value="请输入密码" type="text"><input value="提交" type="submit"><script>$(function(){//输入框中文字颜色控制$("input:not(:last)").css("color","#999");});//用户名框鼠标焦点移进,文字消失$("input:first").click(function () {var check1 = $(this).val();if (check1 == this.defaultValue) {$(this).val("");}});//用户名框鼠标焦点移出,文字显示$("input:first").blur(function () {$(this).val(this.defaultValue);});//密码框鼠标焦点移进,文字消失$("input:eq(1)").click(function () {var check2 = $(this).val();if (check2 == this.defaultValue) {$(this).val("");}//密码框鼠标焦点移出,文字显示$("input:eq(1)").blur(function () {$(this).val(this.defaultValue);});})</script>

---------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html> <head>  <meta http-equiv="Content-Type" content="text/html; charsetGB2312" />  <title>文本框点击时文字消失,失去焦点时文字出现 练习 by 阿会楠</title>   </head> <body>  <input type="text" value="请输入您的姓名" id="myinput" /> </body></html><script language="JavaScript" type="text/javascript">   function addListener(element,e,fn){            if(element.addEventListener){                 element.addEventListener(e,fn,false);             } else {                 element.attachEvent("on" + e,fn);              }       }   var myinput = document.getElementById("myinput");   addListener(myinput,"click",function(){    myinput.value = "";   })   addListener(myinput,"blur",function(){    myinput.value = "请输入您的姓名";   })</script></font><a href="http://js.alixixi.com/">欢迎访问阿里西西网页特效代码站,js.alixixi.com</a>

表单文本框提示样式,点击输入框时,灰色提示文字消失

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">?<html xmlns="http://www.w3.org/1999/xhtml">?<head>?<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />?<title>表单文本框提示样式</title>?<style type="text/css">?<!--?.a1 {?color: #CCCCCC;?}?.a2 {?color: #000;?}?-->?</style>?</head>?<body>?<input name="n" type="text"/>?<input name="n1" type="text"/>?<script language="javascript">?window.onload=function(){?s('n','Your message1');s('n1','Your message2')?}?function g(a){return document.getElementById(a)}?function s(n,v){?with(g(n)){?className='a1';value=v;?onfocus=function(){if(value==v)value='';className='a2'}?onblur=function(){if(value==''){value=v;className='a1'}}?}?}?</script>?</body>?</html>

jquery tip插件:
http://xllily.iteye.com/blog/953557
http://yuanhsh.iteye.com/blog/985641

读书人网 >Web前端

热点推荐