Watermark for Textbox in MVC3

前端 未结 4 1175
不知归路
不知归路 2021-01-12 04:38

How do I set watermark for a texbox in MVC3 .Also if there are multiple textboxes in a web page, how do you write different watermark text for each textbox?



        
4条回答
  •  花落未央
    2021-01-12 05:11

    Try this Jquery .You need to create an image with the watermark text.

    $(document).ready(function () {
    
                /*Watermark for date fields*/
    
                 if ($("#dob").val() == "") {
                    $("#dob").css("background", "#ebebeb url('/Content/images/DateWaterMark.png') no-repeat 1px 0px");
                }
    
                $("#dob").focus(function () {
                    if (watermark == 'MM/DD/YYYY') {
                        $("#dob").css("background-image", "none");
                        $("#dob").css("background-color", "#fff");
                    }
                }).blur(function () {
                    if (this.value == "") {
                        $("#dob").css("background", "#ebebeb url('/Content/images/DateWaterMark.png') no-repeat 1px 0px");
                    }
                });
    
                $("#dob").change(function () {
                    if (this.value.length > 0) {
                        $("#dob").css("background", "#fff");
                    }
                });
    }
    

提交回复
热议问题