Jou*_*man 53 forms html5 checkvalidity
我正在尝试使用表单方法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)};
});
Run Code Online (Sandbox Code Playgroud)
我收到一个错误: object has no method checkValidity()
我究竟做错了什么?
谢谢.
rob*_*rtc 126
尝试:
$('#profileform')[0].checkValidity()
Run Code Online (Sandbox Code Playgroud)
当您选择$('#profileform')获取jQuery选择集时,要访问实际的DOM属性,您必须选择第一个项目.