How do I put a clear button inside my HTML text input box like the iPhone does?

前端 未结 10 2034
太阳男子
太阳男子 2020-12-02 04:21

I want to have a nice little icon that, when clicked will clear the text in the box.

This is to save space rather than having a clear link outside of t

10条回答
  •  失恋的感觉
    2020-12-02 05:16

    I got a creative solution I think you are looking for

    $('#clear').click(function() {
      $('#input-outer input').val('');
    });
    body {
      font-family: "Tahoma";
    }
    #input-outer {
      height: 2em;
      width: 15em;
      border: 1px #e7e7e7 solid;
      border-radius: 20px;
    }
    #input-outer input {
      height: 2em;
      width: 80%;
      border: 0px;
      outline: none;
      margin: 0 0 0 10px;
      border-radius: 20px;
      color: #666;
    }
    #clear {
      position: relative;
      float: right;
      height: 20px;
      width: 20px;
      top: 5px;
      right: 5px;
      border-radius: 20px;
      background: #f1f1f1;
      color: white;
      font-weight: bold;
      text-align: center;
      cursor: pointer;
    }
    #clear:hover {
      background: #ccc;
    }
    
    
    X

    https://jsfiddle.net/qdesign/xn9eogmx/1/

提交回复
热议问题