简体   繁体   中英

checkValidity() causing error in IE9 and below

I'm using jQuery's checkValidity() in ajax form submissions and everything works fine until the form has a select element.

For example, I have a page that shows data based on the user's choice of row count. (Select how many rows of data) ... 10, 20, 30, etc. That's the only form on the page. They select, and all is fine in every browser except IE 9 and below.

Here's the line in the form submission script that's causing the error:

if (!$(this).get(0).checkValidity()) {return false;}

The error that is producing in IE is:

SCRIPT438: Object doesn't support property or method 'checkValidity'

Anyone have an idea of how I can solve this? Works fine in every other browser.

I'm using jQuery's checkValidity() ...

checkValidity() is not a jQuery method, but a native DOM API method. The code you quoted...

if (!$(this).get(0).checkValidity()) {return false;

...gets a reference to the native DOM element (and $(this).get(0) is redundant, it could be replaced simply with this ) and then calls the checkValidity() method on it.

It fails in IE9 and below because they haven't implemented that method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM