CSS selector for text input fields?

后端 未结 9 759
广开言路
广开言路 2020-12-07 07:46

How can I target input fields of type \'text\' using CSS selectors?

9条回答
  •  眼角桃花
    2020-12-07 08:11

    You can use :text Selector to select all inputs with type text

    Working Fiddle

    $(document).ready(function () {
        $(":text").css({    //or $("input:text")
            'background': 'green',
            'color':'#fff'
        });
    });
    

    :text is a jQuery extension and not part of the CSS specification, queries using :text cannot take advantage of the performance boost provided by the native DOM querySelectorAll() method. For better performance in modern browsers, use [type="text"] instead. This will work for IE6+.

    $("[type=text]").css({  // or $("input[type=text]")
        'background': 'green',
        'color':'#fff'
    });
    

    CSS

    [type=text] // or input[type=text] 
    {
        background: green;
    }
    

提交回复
热议问题