开发者

How do I mark a field as required when it contains a default value, using bassistance jquery validation plugin?

Basically all fields in the form are supposed to have a default value if the u开发者_如何学Cser doesn't input anything in the field. Is it possible to force the validation plugin to show errors, like required field, while overlooking these default values?


You can use placeholder tag, but it only works in browsers that support html5

<input name="search" type="text" placeholder="Enter some keywords..." />


Add a class eg. clearDefault to your required field and clear it on focus

$(document).ready(function(){
    $(".clearDefault").focus(function () { $(this).val('');});
    $(".validate").validate();
});

<form class = "validate">
<input type = "text" class = "required clearDefault" name = "foo" value = "Please enter a foo"/>
</form>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜