我正在尝试使用表单方法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()
我究竟做错了什么?
谢谢.
鉴于以下文件:
<input pattern="[a-z]"/>
Run Code Online (Sandbox Code Playgroud)
在不填写输入的情况下,运行:
document.querySelector('input').checkValidity()
Run Code Online (Sandbox Code Playgroud)
退货true.
由于空输入不匹配[a-z],为什么HTML5 checkValidity()会返回true?
我维护着一个庞大的(约5000个文档)教育有用的资料库。我已经将它们打包为ePub,并且也希望将它们打包为SCORM对象。我已经在生成的epub中添加了基本的SCORM功能,但是我发现很难使用标准的SCORM工具来确定我是否正确。为了确保ePubs的有效性,我使用了epubchecker(https://github.com/IDPF/epubcheck),它可以很好地满足要求。
有人可以告诉我是否存在一种验证SCORM对象的方法,或者是否存在适合SCORM验证的任何库?
我的表单中有两个复选框,所有其他表单字段都使用必需的 HTML 属性,以便我可以在提交时运行验证。这有点不同,因为我有两个复选框输入字段,并且我必须要求至少检查一个。这是一个例子:
$('.frm-Submit').on('submit', submitFrm);
function submitFrm(e){
e.preventDefault(); // Prevnts default form submit.
var $checkbox = $('.account-type');
$checkbox.on('change', function(){
var checked = false;
$checkbox.each(function(){
checked = checked || $(this).is(':checked')
});
$checkbox.prop('required', !checked)
});
console.log('Submit form.')
}Run Code Online (Sandbox Code Playgroud)
.form-group.required .control-label:after {
content: " *";
color: red;
}Run Code Online (Sandbox Code Playgroud)
<script language="javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script language="javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<form name="frmSave" id="frmSave" class="frm-Submit" autocomplete="off">
<div class="form-group required">
<label class="control-label" for="account"><span class="label label-primary">Account Type:</span></label>
<div class="checkbox">
<label for="user">
<input type="checkbox" name="frm_isuser" id="frm_isuser" data-toggle="collapse" data-target="#user-account" required class="account-type"> …Run Code Online (Sandbox Code Playgroud)