0

我使用下面的链接 http://www.mkyong.com/jquery/jquery-watermark-effect-on-text-input/在我的输入中添加了水印

一旦我添加了我需要使用 jquery 进行的验证,就会停止工作。我怎样才能让我的验证和水印都工作?

<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');
    }
});
}
4

1 回答 1

0
<input type="text" name="key" id="searchInput" placeholder="what's up"/> worked for me

– kandroid 2 月 18 日 15:19

于 2013-02-27T02:14:51.183 回答