简体   繁体   English

checkValidity()在IE9及以下版本中导致错误

[英]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. 我在ajax表单提交中使用jQuery的checkValidity() ,并且一切正常,直到表单具有select元素为止。

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. (选择数据行数)... 10、20、30等。这是页面上的唯一形式。 They select, and all is fine in every browser except IE 9 and below. 他们选择,并且在IE 9及以下版本的所有浏览器中都可以正常运行。

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: 在IE中产生的错误是:

SCRIPT438: Object doesn't support property or method 'checkValidity' SCRIPT438:对象不支持属性或方法“ checkValidity”

Anyone have an idea of how I can solve this? 有人知道我该如何解决吗? Works fine in every other browser. 在所有其他浏览器中都可以正常工作。

I'm using jQuery's checkValidity() ... 我正在使用jQuery的checkValidity() ...

checkValidity() is not a jQuery method, but a native DOM API method. checkValidity()不是jQuery方法,而是本机DOM API方法。 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. ...获取对本机DOM元素的引用( $(this).get(0)是多余的,可以简单地用this代替),然后在其上调用checkValidity()方法。

It fails in IE9 and below because they haven't implemented that method. 在IE9及以下版本中,此操作失败,因为他们尚未实现该方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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