zoukankan      html  css  js  c++  java
  • placeholder

    打开一个那边发过来的页面,里面全是placeholder。没见过,一时气愤全部ko,用传统的方法都能搞定的东西,为啥要标新立异!

    后来发现如果想在input password里显示个把汉字,还真是不容易,总不能让我加个absolute的label吧。于是乎又想起了之前的placeholder,在手机端的页面,还是蛮支持的,拿来用用,也好。。。

    解决问题:

    input的占位符,不必再自己写提示文字以及focus blur的判定语句

    效果:

    代码:

                  //检测是否支持place-holder
                  function placeHolderSupport(){
                      return "placeholder" in document.createElement("input");
                  }
    
                  if(!placeHolderSupport()){
                      $(document.body).addClass("unsupport_placeholder");
                      $(".input-item").focus(function(){
                          $(this).parent().find("label").hide();    
                      }).blur(function(){
                          var el = $(this),
                              val = el.val();
                              console.log("dd",val);
                          if(val.length == 0){
                              el.parent().find("label").show();
                          }
                      })
                  }
    
            <input placeholder="密码:" class="input-item" type="password" id="password"  name="password" value="" required />
    

      

  • 相关阅读:
    铁大电梯调度需求分析
    结对开发2
    四则运算3
    团队开发——冲刺2.d
    团队开发——冲刺2.c
    团队开发——冲刺2.b
    团队开发——冲刺2.a
    团队开发——冲刺1.g
    团队开发——冲刺1.f
    团队开发——冲刺1.e
  • 原文地址:https://www.cnblogs.com/frostbelt/p/2641450.html
Copyright © 2011-2022 走看看