Jqueryvalidate bug solution in ie8 _ jquery-js tutorial
Source: Internet
Author: User
The jquery Form validation plug-in validate is used in the project, but there is a bug in ie8. Below is a good solution, if you need it, you can refer to the following project and use the jquery Form Verification plug-in validate. It has always been a simple verification and has not been used for a slightly complex application, recently, the project's requirements for applications have been improved. There are two submit buttons in a page, and form verification is bound to the button click event, as shown below.
Then the valid () function of the plug-in is used naturally:
This does achieve the expected results, but there is a problem in ie8. The valid () method always returns false, and all fields will be used as required field verification, after a long struggle, because jquery's plug-in code is very complex, it was very difficult at the beginning. Later, I checked it step by step and found the problem. The problem lies in the attributeRules () function:
This function applies the verification framework when you write the verification rules on the page instead of in the script. Technically, it is reasonable to handle required, but for ie8. Ie8 executes the following branches:
Therefore, all fields are verified as required fields. After testing, the last two methods can be solved:
The first is to find the following code in the rules () method and comment out the call to attributeRules (). The reason for this is that the verification is rarely written to the page, of course, this is definitely not the best solution. Let's look at the second one.
The second solution requires two things: first, modify the attributeRules () method and replace the getAttribute () method with the attr () method. Note that getAttribute () is a js method, while attr () is a jquery method. The objects used are different. In fact, after this change, the bug in ie8 has been solved, however, this problem occurs again in ie7, so you need to use the latest jquery. I used jquery1.10.2 for testing.
Oh, by the way, do not forget to block the default form events.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service