我使用以下链接为我的输入添加了水印 http://www.mkyong.com/jquery/jquery-watermark-effect-on-text-input/
一旦我添加了使用jquery unobtrusive的所需验证停止工作。 如何才能使我的验证和水印都能正常工作?
<script src="@Url.Content("~/Scripts/jquery-1.7.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<div class="editor-field">
@Html.EditorFor(model => model.Person.PersonName)
@Html.ValidationMessageFor(model => model.Person.PersonName)
</div>
$(document).ready(function () {
var watermark = 'Person Name';
init, set watermark text and class
$('#Person_PersonName').val(watermark).addClass('watermark');
if blur and no value inside, set watermark text and class again.
$('#Person_PersonName').blur(function () {
if ($(this).val().length == 0) {
$(this).val(watermark).addClass('watermark');
}
});
if focus and text is watermrk, set it to empty and remove the watermark class
$('#Person_PersonName').focus(function () {
if ($(this).val() == watermark) {
$(this).val('').removeClass('watermark');
}
});
}
答案 0 :(得分:0)
<input type="text" name="key" id="searchInput" placeholder="what's up"/> worked for me
- kandroid 2月18日15:19