ie8不相容input的placeholder屬性但是要實現其效果的方法

來源:互聯網
上載者:User

標籤:one   targe   對象   相容   play   required   代碼   想法   color   

 

通過學習前輩的思想,個人想法整理如下:

  1. 通過兩個元素標籤,仿造出placeholder的內容
  2. 使用position定位好兩個元素標籤
  3. 第一要隱藏兩個元素標籤display:none,在<!--[if gte IE 8]><![endif]-->中設定style樣式為display:inline-block
  4. 使用js控制效果,通過給頁面綁定點擊事件並且利用target對象做判斷,控制兩個元素標籤的顯藏:
  • 點擊的對象是元素標籤,當前點擊對象隱藏,判斷另外的輸入框值是否為空白,是否隱藏顯示第二個元素標籤
  • 點擊的對象時輸入框,當前輸入框的元素標籤隱藏,判斷另外的輸入框值是否為空白,是否隱藏顯示第二個元素標籤
  • 點擊是其他對象,判斷所有輸入框的值是否為空白,是否顯示或隱藏兩個元素標籤

HTML代碼如下:

<div>
<div class="Account_img">
<div class="ion-person-stalker"></div>
</div>
<input id="Account" name="Account" type="text" value="" placeholder="Username賬戶" class="valid">
<span class="show_placeholder" id="span1">Username賬戶</span>
</div>

<div>
<div class="password_img">
<div class="fa fa-key"></div>
</div>
<input data-val="true" data-val-required="請填寫使用者密碼" id="Password" name="Password" type="password" placeholder="Password密碼">
<span class="show_placeholder" id="span2">Password密碼</span>
</div>

 CSS代碼略

 JS代碼如下:

<!--[if gte IE 8]><script type="text/javascript">    $(document).click(function (e) {        var e = e || window.event;        var target = e.srcElement || e.target;        if (target.id == ‘span1‘) {            controll_input1();            $(‘#Account‘).focus();        } else if(target.id == ‘span2‘){            controll_input2();            $(‘#Password‘).focus();        }else if(target.id=="Account"){            controll_input1();        }else if(target.id=="Password"){            controll_input2();        }else{            if ($(‘#Account‘).val() == "") {                $(‘#span1‘).show();            }            if ($(‘#Password‘).val() == "") {                $(‘#span2‘).show();            }        }    });    function controll_input1(){        $(‘#span1‘).hide();        if ($(‘#Password‘).val() == "") {            $(‘#span2‘).show();        }    }    function controll_input2(){        $(‘#span2‘).hide();        if ($(‘#Account‘).val() == "") {            $(‘#span1‘).show();        }    }</script><style>    .show_placeholder {        display: inline-block;    }</style><![endif]-->

 

ie8不相容input的placeholder屬性但是要實現其效果的方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.