Html 从IE10中的孤立控件提交时使用必需属性进行表单验证
在HTML5中,我必须提交我的表单。为了支持IE10,我使用以下方法:Html 从IE10中的孤立控件提交时使用必需属性进行表单验证,html,forms,validation,internet-explorer-10,Html,Forms,Validation,Internet Explorer 10,在HTML5中,我必须提交我的表单。为了支持IE10,我使用以下方法: jQuery(document).delegate('input[form][type="submit"], button[form][type="submit"]', 'click', function() { form_selector = "form#" + jQuery(this).attr("form") + ""; console.log("submitting IE10 form from an orp
jQuery(document).delegate('input[form][type="submit"], button[form][type="submit"]', 'click', function() {
form_selector = "form#" + jQuery(this).attr("form") + "";
console.log("submitting IE10 form from an orphaned control:" + form_selector);
jQuery(form_selector).submit();
});
chrome和firefox提交时不需要这段代码,并像往常一样使用required属性处理输入,如果任何一个所需输入为空,则停止提交并显示弹出消息
<input required/>
IE10需要上面的javascript来提交表单,但是,如果任何具有必需属性的输入为空,则通常的弹出消息不会出现在空控件上。如果我将控件移动到表单下,并且不使用submit功能,则弹出消息显示正常
关于如何在IE10中调用submit时显示弹出窗口,有什么建议吗
编辑:这里有一个JSFIDLE演示正在发生的事情:
在IE10和chrome/firefox中都可以尝试,如果您使用该方法,则可以激活所需的提交按钮以启动验证
下面是使用.trigger的示例的更新版本
为了让其他人更容易帮助您,请在这里或JSFIDLE或代码共享中添加更多代码。是的,我在寻找调用submit时丢失的秘密调用。如果没有人能回答这个问题,我会接受这个答案。我更新了答案。这是否符合您正在尝试的操作?
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript">
$( document ).ready( function() {
$('.btn-primary').click(function(event) {
$("form#test_form input[type=submit]").trigger( "click" );
});
});
</script>
</head>
<body>
<h2>
Try this in chrome and then in IE10
<button type="submit" class="btn btn-primary" form="test_form">
im outside the form
</button>
</h2>
<div class="dashWidget autoHeight" data-pagination='true'>
<form id="test_form">
Leave me blank:<input type="text" value="" required />
<input type="submit" value="im in the form!"/>
</form>
</div>
</body>
</html>
$('.email').bind('input', function () {
//We need to reset it to blank or it will throw an invalid message.
this.setCustomValidity('');
if (!this.validity.valid) {
this.setCustomValidity("Dude '" + this.value + "' is not a valid email. Try something like "+
"jim@jboss.org. And no we are not checking if it actually works, we are just looking "+
"for the @ sign. ");
}
});