水印使用显示MVC3剃刀(提示= [英] Watermark for MVC3 razor using Display(Prompt=
问题描述
我想显示水位为我Html.Editorfor,
I am trying to display water mark for my Html.Editorfor ,
下面是我的视图模型
[Display(Prompt="This is a WaterMark")]
[DisplayFormat(DataFormatString = "{0:MM/dd/yyy}", ApplyFormatInEditMode = true)]
public DateTime Dob { get; set; }
下面是我的看法。
@Html.EditorFor(model => model.Dob)
这是我EditorTemplate String.cshtml在\\查看\\共享\\ EditorTemplates \\ String.cshtml
here is my EditorTemplate String.cshtml at \Views\Shared\EditorTemplates\String.cshtml
@Html.TextBox("",ViewData.TemplateInfo.FormattedModelValue, new { @class="text-box single-line", placeholder = ViewData.ModelMetadata.Watermark })
我试过这个按照这个线程。但我水印一直没有露面,但为什么?
I tried this by following this thread .But my watermark never showed up ,but why ?
鸭preciate你的帮助来解决这个
Appreciate your help to resolve this
推荐答案
使用显示水印(提示从来没有为我工作,但随着这个jQuery您可以在文本框中显示的水印。在这里我使用的图像到位水印。你需要创建一个水印文字的图像。
watermarking using Display(Prompt never worked for me. But with this jquery you can show watermark on your text box .Here I am using an image in place of watermark.You need to create an image of 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");
}
});
}
这篇关于水印使用显示MVC3剃刀(提示=的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!