我正在尝试使用表单方法checkValidity()。
http://html5test.com/告诉我,我的浏览器(Chrome)支持表单级checkValidity方法。
但是,使用jsfiddle http://jsfiddle.net/LcgnQ/2/我尝试了以下html和javascript片段:
<form id="profileform" name="profileform">
<input type="text" id="firstname" required>
<input type="button" id="testbutton" value="Test">
</form>
$('#testbutton').bind('click',function(){
try{
alert($('#profileform').checkValidity());
}
catch(err){alert('err='+err)};
});
我收到一个错误:object has no method checkValidity()
我究竟做错了什么?
谢谢。
尝试:
$('#profileform')[0].checkValidity()
当您选择$('#profileform')
时,您将获得一个jQuery对象数组。要访问实际的DOM属性,必须选择数组中的第一个项目,即原始DOM元素。