Created
October 11, 2012 08:32
-
-
Save Megic/3870999 to your computer and use it in GitHub Desktop.
Js:focus-jquery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //使用jquery | |
| //捕获焦点函数支持input以及textarea标签 | |
| Mj_fc("#mjask .ma_t","请输入标题:",'1'); | |
| Mj_fc("#mjask textarea","内容字数控制在2-200个字符之间",'2'); | |
| function Mj_fc(obj,text,ty){ | |
| var sct; | |
| sct= $(obj); | |
| sct.focus(function(){ | |
| if(ty==2&&$(this).html()!=text)return; | |
| if(ty==1&&$(this).val()!=text)return; | |
| if(ty==2){$(this).html("");return;} | |
| sct.val(""); | |
| }).blur(function(){if($(this).val()!= ""){ return;}if(ty==2){sct.html(text);return;};sct.val(text)}); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment