little 'x' in textfield input on the iphone in mobileSafari?

后端 未结 6 620
Happy的楠姐
Happy的楠姐 2020-12-16 15:28

I have been looking everywhere for this without any luck. If you go to google.com on the iphone when you focus in on the search field a little \'x\' appears all the way in t

6条回答
  •  佛祖请我去吃肉
    2020-12-16 15:56

    And this is my jQuery version, it hides it at the start, and if the user deletes what is typed it will remove the 'x'. Also when they have removed the text with the button it will hide the 'x' too.

    html:

    
    X
    

    JavaScript:

    $('.clear_input').hide();   
        $('#search').keyup(function() {
    
            var search = $(this).val().replace(/^\s+|\s+$/g,"");
    
            if (search.length >= 1) {
                $('.clear_input').show();
            } else {
                $('.clear_input').hide();
            }
    
            $('.clear_input').click(function() {
                $('#search').val('');
                $('.clear_input').hide();
            }); 
        });
    

    The JavaScript version is faster than the jQuery version of course.

提交回复
热议问题