IE跟FF输入值监听-------自写

来源:互联网 发布:优化安卓手机 编辑:程序博客网 时间:2024/06/05 03:42

兼容所有浏览器 IE6-IE9 FF          

Input_Monitoring("#UserName", function () {
                     if ($(this).val() == "") {
                         $("#idPlaceholder").show();
                     } else {
                         $("#idPlaceholder").hide();
                     }
                 });
                 Input_Monitoring("#Password", function () {
                     if ($(this).val() == "") {
                         $("#pwdPlaceholder").show();
                     } else {
                         $("#pwdPlaceholder").hide();
                     }
                 });
                 $("#UserName").focus();


/*提示框*/

             function msg(msg,title) {
                 $.jBox.alert(msg,title);
             }
             function middle_height(id) {
                 var h = $(id).height();
                 var w = $(window).height();
                 var top = (w - h) / 2;
                 if (top > 0) { return top+ "px"; } else { return "0px"; }
             }
             function Input_Monitoring(id,fun) {
                 $(id).on("input propertychange change blur focus keyup", fun);
             }

             /*绑定事件*/
             function EventFun(name,ac,fun) {
                     $(name).bind(ac,fun);
                 }
             /*增加class*/
             function AddCls(name, classname) {
                 $(name).addClass(classname);
             }
             /*删除class*/
             function ReCls(name, classname) {
                 $(name).removeClass(classname);

             }


 Input_Monitoring("#UserName",function () {
                     if ($(this).val() == "") {
                         $("#idPlaceholder").show();
                     } else {
                         $("#idPlaceholder").hide();
                     }
                 });
                 Input_Monitoring("#Password", function () {
                     if ($(this).val() == "") {
                         $("#pwdPlaceholder").show();
                     } else {
                         $("#pwdPlaceholder").hide();
                     }
                 });

 <div id="idInputLine" class="login_iptbox showPlaceholder">
                        <%: Html.TextBoxFor(m => m.UserName, new { Class = "input login_ipt", autocomplete = "off" })%>
                        
                        <label for="UserName" class="placeholder" id="idPlaceholder">
                            登录帐号</label>
                    </div>
                    <div class="forgetPwdLine">
                        
                    </div>
                    <div id="pwdInputLine" class="login_iptbox showPlaceholder">
                        <%: Html.PasswordFor(m => m.Password, new { Class = "input login_ipt", autocomplete = "off" })%>
                        <label for="Password" class="placeholder" id="pwdPlaceholder">
                            密码</label>
                    </div>