How to add html placeholder to select2?

后端 未结 4 1673
南旧
南旧 2021-01-18 06:39

I want to add one icon to placeholder like this

$(\"#tag_list\").select2({
    allowClear: true,
    placeholder: \"         


        
4条回答
  •  离开以前
    2021-01-18 07:18

    Im guessing your are trying to use font-awesome. They have a cheatsheet with unicodes here: http://fortawesome.github.io/Font-Awesome/cheatsheet/ This can be placed in the placeholder in html:

    
    

    Remember to add the on the input element:

    font-family: 'FontAwesome'
    

    This is not supported by all browsers so you might want to do a fallbackhack with the :before element.

    .wrapper:before {
      font-family: 'FontAwesome';
      color:red;
      position:relative;
      content: "\f042";
    }
    

    Last fallback is to actually use an image like this:

    background-image: url(http://www.levenmetwater.nl/static/global/images/icon-search.png);
    background-position: 10px center;
    background-repeat: no-repeat;
    

    If you want it to remove the icon on focus, add this:

    input:focus {
     background-position: -20px center;
     text-indent: 0;
     width: 50%;
    }
    

提交回复
热议问题