How do I clear a search box with an 'x' in bootstrap 3?

前端 未结 9 1552
情歌与酒
情歌与酒 2020-12-12 10:44

Having some trouble with bootstrap, so some help would be awesome. Thanks

What I would like:(top part)

\

9条回答
  •  无人及你
    2020-12-12 11:33

    Do not bind to element id, just use the 'previous' input element to clear.

    CSS:

    .clear-input > span {
        position: absolute;
        right: 24px;
        top: 10px;
        height: 14px;
        margin: auto;
        font-size: 14px;
        cursor: pointer;
        color: #AAA;
    }
    

    Javascript:

    function $(document).ready(function() {
        $(".clear-input>span").click(function(){
            // Clear the input field before this clear button
            // and give it focus.
    
            $(this).prev().val('').focus();
        });
    });
    

    HTML Markup, use as much as you like:

    Pizza:
    Pasta:

提交回复
热议问题