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

前端 未结 9 1535
情歌与酒
情歌与酒 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:24

    Thanks unwired your solution was very clean. I was using horizontal bootstrap forms and made a couple modifications to allow for a single handler and form css.

    html: - UPDATED to use Bootstrap's has-feedback and form-control-feedback

     

    javascript:

    $(".hasclear").keyup(function () {
        var t = $(this);
        t.next('span').toggle(Boolean(t.val()));
    });
    $(".clearer").hide($(this).prev('input').val());
    $(".clearer").click(function () {
        $(this).prev('input').val('').focus();
        $(this).hide();
    });
    

    example: http://www.bootply.com/130682

提交回复
热议问题