zoukankan      html  css  js  c++  java
  • input 框的 placeholder 另类实现

      昨天偶然想到了插入图片,但是图片不够灵活,文字的话想怎么写就怎么写。于是就又搞出了一种实现方式。

      方法主要在于灵活,将 ie 与 chrome 的差异性尽量降低。

      这里使用 angular 最终可以封装为指令,利于调用等~

      下面我们上代码:

    <!DOCTYPE html>
    <html ng-app='myApp'>
        <head>
            <meta charset='utf-8'>
            <script src='angular.js'></script>
            <script src='jquery-1.11.3.js'></script>
            <style>
                .d1 {
                    position: relative;
                }
                .input1 {
                    background: transparent;
                }
                .span1 {
                    font-size: 13.33px;
                    color: #999;
                    position: absolute;
                    top: 4px;
                    left: 2px;
                    z-index: -1;
                }
            </style>
        </head>
        <body>
            <div ng-controller='myCtrl'>
                <div class='d1'> 
                    <input type='text' ng-model="inputValue" class="input1"/>
                    <span  class='span1' ng-if="!inputValue">{{message}}</span>
                </div>
            </div>
            <script>
                angular.module("myApp",[])
                .controller("myCtrl",function($scope){
                    $scope.message = '请输入';
                })
            </script>
        </body>
    </html>

      看起来很简单,说的没错,压根就不难,思路想当简单:利用一个 span 装载提示词,将其悬浮在 input 框下即可~~~

    ie9:

     

    chrome:

  • 相关阅读:
    slice()、substring()、substr()的区别用法
    程序员如何快速上手一个自己不太熟悉的新项目?有什么技巧?
    计算重复字符串长度
    计算机视觉算法研发岗招聘要求
    C++进阶STL-2
    C++进阶STL-1
    拼硬币
    序列找数
    寻找合法字符串
    字符串是否由子串拼接
  • 原文地址:https://www.cnblogs.com/guofan/p/7169457.html
Copyright © 2011-2022 走看看