Input with Watermark (css & Jquery)

后端 未结 3 2002
你的背包
你的背包 2020-12-06 01:36

JS

$(document).ready(function () {
    $(\":input[data-watermark]\").each(function () {
        $(this).val($(this).attr(\"data-watermark\"));
        $(th         


        
3条回答
  •  半阙折子戏
    2020-12-06 02:13

    Your desired behaviour of "Input with Watermark" has already been done - it's called the placeholder attribute. It works in modern browsers.

    For older browsers, you should use a jQuery plugin to emulate placeholder for you.

    Lastly, to set the colour, you need CSS similar to this:

    .placeholder {
        color: #a8a8a8;
    }
    ::-webkit-input-placeholder {
        color: #a8a8a8;
    }
    :-moz-placeholder {
        color: #a8a8a8;
    }
    

    Unfortunately, you can't combine the above rules; it won't work.

提交回复
热议问题