jQuery change placeholder text color

前端 未结 5 957
甜味超标
甜味超标 2020-12-05 23:35

Is it possible to use \"::-webkit-input-placeholder\" with jQuery to set a color for the placeholder text?

Something like this:

$(\"input::-webkit-in         


        
5条回答
  •  心在旅途
    2020-12-06 00:11

    If you don't have a stylesheet, and want to inject CSS dynamically you can use the following:

    $('body').append('')
    

    Just use my_class and the color for the placeholder.

    It's handy to have a general purpose function:

    function change_placeholder_color(target_class, color_choice) {
        $("body").append("")
    }
    

    Usage:

    change_placeholder_color('.my_input', 'red')
    

提交回复
热议问题