Javascript 表单提交在safari中不起作用并且在所有其他浏览器中都起作用? 函数submitAlbum(){ var frm=document.getElementById(“客户注册”); frm.action=“CustomerinfoServlet?formidentity=domobileappRegistrations”; frm.submit(); } 姓名*: 电子邮件Id*:
除了safari(使用的版本是-5.1.7)和iPad外,上述表单在所有浏览器中都可以正常工作。在safari中,表单没有验证html5必需属性并使表单提交,而在其他浏览器(chrome、firefox、IE)中工作正常。那么有人能告诉我如何使用safari完成吗?如果有任何帮助,我们将不胜感激。HTML表单验证是一项非常重要的工作。 它是一种设置必填字段和字段类型的方法,不需要JavaScript Safari中的部分支持是指当试图提交带有必填字段的表单时,没有通知。IE10 mobile中的部分支持是指在阻止提交时没有警告 另外,在Firefox或Opera中不完全支持使用不同颜色的边框,使用单独的类进行样式设计在这两种情况下都很有效 在Chrome中,属性Javascript 表单提交在safari中不起作用并且在所有其他浏览器中都起作用? 函数submitAlbum(){ var frm=document.getElementById(“客户注册”); frm.action=“CustomerinfoServlet?formidentity=domobileappRegistrations”; frm.submit(); } 姓名*: 电子邮件Id*: ,javascript,html,safari,submit,Javascript,Html,Safari,Submit,除了safari(使用的版本是-5.1.7)和iPad外,上述表单在所有浏览器中都可以正常工作。在safari中,表单没有验证html5必需属性并使表单提交,而在其他浏览器(chrome、firefox、IE)中工作正常。那么有人能告诉我如何使用safari完成吗?如果有任何帮助,我们将不胜感激。HTML表单验证是一项非常重要的工作。 它是一种设置必填字段和字段类型的方法,不需要JavaScript Safari中的部分支持是指当试图提交带有必填字段的表单时,没有通知。IE10 mobile中的
formnovalidate
对
元素不起作用,但对
元素起作用
您可以尝试对所有不支持HTML5required
属性的浏览器使用下面的脚本:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
<link rel="icon" type="image/png" href="images/fav_icon.png">
<script>
function submitAlbum(){
var frm=document.getElementById("custRegistration");
frm.action="CustomerinfoServlet?formidentity=domobileappRegistrations";
frm.submit();
}
</script>
</head>
<body style=" background-color:#f9f9f9" onload="DrawCaptcha();">
<!--start mainwrap-->
<div id="mainwrap">
<!--start midwrap-->
<div id="midwrap">
<div style="width: 100%; background-repeat:no-repeat; margin-top:15px; height:546px; background-image: url('images/form_background.png')">
<br/><br/><br/>
<div style="margin: 0 auto; background-color: #ffffff; opacity:0.9; border: 1px solid #D7EBFF; width: 400px; padding: 15px; height: 440px; margin-left: 56%;">
<form class="form" name ="custRegistration" id="custRegistration" onsubmit="return submitAlbum(this)" action="download.jsp" method="post" >
<p class="name">
<label for="name">Name <span style="color:red">*</span>:</label>
<input type="text" name="name" id="name" placeholder="" pattern="[A-Za-z ]{3,20}" required/>
<input type="hidden" id="formidentity" name="formidentity" value="domobileappRegistrations"/>
</p>
<p class="email">
<label for="email">Email Id <span style="color:red">*</span>:</label>
<input type="email" name="email" id="email" pattern="((\w+\.)*\w+)@(\w+\.)+(com|org|net|us|info|biz|co)" required aria-required="true" placeholder="" required/>
</p>
<p class="submit">
<label for="download" id="freetrail"></label>
<input type="submit" value="Submit" />
</p>
</form>
</div>
</div>
</div>
</div>
<div style="clear:both"></div>
</body>
</html>
编辑:
作为替代方案,您可以以这样的基本方式使用(如果您遵循链接,将提供有关如何使用它的更多详细信息):
这是最兼容浏览器的解决方案。所需的HTML
不应该是您唯一的验证,只是一个旁注上面的代码与jQuery<1.9.x兼容,请使用jQuery 1.8.2测试它(因为使用了$.browser
)…或者作为替代,包括jQuery Migrate
插件以及最新的jQuery和代码。@bodiO我用jQuery 1.8.2尝试过,它显示了相同的结果…如果它对你有用,如果时间允许,你可以请你用jsfiddle更新我的代码吗???提前谢谢…@bodiO谢谢你的回答,但很抱歉,我得到了正确的答案输出。。!!
//Required attribute fallback
$('#form').submit(function() {
if (!attributeSupported("required") || ($.browser.safari)) {
//If required attribute is not supported or browser is Safari
//(Safari thinks that it has this attribute, but it does not work),
//then check all fields that has required attribute
$("#form [required]").each(function(index) {
if (!$(this).val()) {
//If at least one required value is empty, then ask to fill all required fields.
alert("Please fill all required fields.");
return false;
}
});
}
return false; //This is a test form and I'm not going to submit it
});
$(document).ready(function() {
// validate the form when it is submitted
$("#form").validate();
});