首頁 > web前端 > js教程 > 主體

兩種JS實作Input裡加入小圖示的方法

小云云
發布: 2017-12-22 10:36:53
原創
4102 人瀏覽過

本文我們主要介紹兩種JS實現Input裡添加小圖標的方法,大家在做網站的時候,經常需要在input裡面添加小圖標功能,看似功能很簡單,但是實現起來還是有點技巧的,下面小編跟大家介紹下JS Input裡加入小圖示的兩種方法,需要的朋友參考下吧,希望能幫助大家。

方法一

將小圖示當作input的背景來插入,直接上程式碼:


<style type="text/css">
      *{
        margin: 0;
        padding: 0;
      }
      input{
        border: none;
      }
      .box{
        height: 50px;
        background: yellow;
      }
      .box input{
        width: 200px;
        height: 30px;
        border-radius: 15px;
        margin: 10px 0;
        background: url(image/search.gif) no-repeat;
        background-color: white;
        background-position: 3px;
        padding-left: 30px;
        border: 1px solid black;
        outline: none;
      }
    </style>
  </head>
  <body>
    <p class="box">
      <input type="text" class="username" value="搜索"/>
    </p>
  </body>
登入後複製

方法二

使用i 標籤插入


<style type="text/css">
      *{
        margin: 0;
        padding: 0;
      }
      .box{
        width: 200px;
        position: relative;
      }
      .box .icon-search{
        background: url(image/search.gif) no-repeat;
        width: 20px;
        height: 20px;
        position: absolute;
        top: 6px;
        left: 0;
      }
      .box .username{
        padding-left: 30px;
        height: 25px;
      }
    </style>
  </head>
  <body>
    <p class="box">
      <i class="icon-search"></i>
      <input type="text" class="username" value="搜索"/>
    </p>
  </body>
登入後複製

相關推薦:

JS 仿支付寶input輸入顯示數位放大鏡

#javascript input輸入框模糊提示功能詳解

#區別input框和按鈕的方法

#

以上是兩種JS實作Input裡加入小圖示的方法的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!