jQuery Watermarked input and validation

后端 未结 5 1546
小鲜肉
小鲜肉 2020-12-19 12:38

On a HTML page I have an inputbox that has a \'watermark\' on it when it is empty. (eg: \"enter text here...\"). Kind of like this: http://digitalbush.com/projects/watermark

5条回答
  •  一向
    一向 (楼主)
    2020-12-19 12:59

    I'm using the Watermark plugin for jQuery, but my situation was similar:

    http://code.google.com/p/jquery-watermark/

    It uses a classname for the display of the watermark. (I'm not sure if the DigitalBrush version uses a class or not.) I've modified the above function to use jQuery's hasClass() function to determine whether or not the field is evaluated as "empty" based on currently assigned classes.

    function notWatermark(value, element){
     return !$(element).hasClass("waterMarkClass");
    }
    $.validator.addMethod("notWatermark", notWatermark, "Required.");
    

提交回复
热议问题