开发者

jQuery Validate Plugin hide/show error container

开发者 https://www.devze.com 2023-01-01 12:29 出处:网络
I would like to render error containers invisible and show them only when errors appear (and hide again when they disappear). What 开发者_如何学编程is the easiest whay to implement such behaviour?The

I would like to render error containers invisible and show them only when errors appear (and hide again when they disappear). What 开发者_如何学编程is the easiest whay to implement such behaviour?


The best way to implement that would to use the showerrors option.

the showerrors option allows you to define a function for how you would like your errors to display. You can manipulate this function to hide and show errors.

here are the docs


Set your error divs up similar to:

<div id='errors' style="display: none;">Sample Error</div>

Use jQuery's .show() method to display the div like:

if (errors == true){
    $("#errors").show()
}

If need be use .html() to customize the error like:

if (errors == specificError){
    $("#errors").html('A specific error has occurred')
    $("#errors").show()
}

And always remember, the jQuery API site is your best friend.

EDIT: I just noticed that you mention the jq validate plugin, specify which plugin you are using and I can provide more specific samples if need be.

0

精彩评论

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