How do I add a “search” button in a text input field?

前端 未结 7 1403
梦毁少年i
梦毁少年i 2020-11-27 18:49

How do I create a similar “search” element to the one in this site?

\"enter

If

7条回答
  •  抹茶落季
    2020-11-27 19:32

    I'd like to plug a new jQuery plugin I wrote because I feel it answers to the OP's request. It's called jQuery.iconfield: https://github.com/yotamofek/jquery.iconfield.

    It lets you easily add an icon to the left side of your text field. For using the icon as a button, you can easily bind to the 'iconfield.click' event, which is triggered when the user clicks the icon. It also takes care of changing the cursor when the mouse is hovering over the icon.

    For instance:

    $('#search-field').iconfield( {
        'image-url':   'imgs/search.png', // url of icon
        'icon-cursor': 'pointer'          // cursor to show when hovering over icon
    } );
    $('#search-field').on( 'iconfield.click', function( ) {
        $('#search-form').submit()
    }
    

    I would love to get some feedback on my work.

提交回复
热议问题