HTML5 for HTML5必填字段设置为在Safari中使用 [英] JavaScript for HTML5 required field set up to work in Safari

查看:143
本文介绍了HTML5 for HTML5必填字段设置为在Safari中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下脚本来更改输入元素的HTML5 必需属性。我很想知道是否有办法修改此脚本以使其在Safari浏览器中也能正常工作,因为Safari不支持此属性。

I am using the following script to change the HTML5 required attribute of my input elements. I am wonder whether there is a way to modify this script to make it also work in Safari browsers, since Safari does not support this attribute.

这是脚本:

$(document).ready(function() {
    $_POST = array();
    var elements = document.getElementsByTagName("INPUT");
    for (var i = 0; i < elements.length; i++) {
        elements[i].oninvalid = function(e) {
            e.target.setCustomValidity("");
            if (!e.target.validity.valid) {
                e.target.setCustomValidity("This field can't be blank");

            }
        };
        elements[i].oninput = function(e) {
            e.target.setCustomValidity("");

        };
    }
})


推荐答案

点击此处查看此页面。它包含一个应该添加所需功能的hacky解决方案

Check out this page here. It contains a hacky solution that should add the desired functionality

http://www.html5rocks.com/en/tutorials/forms/constraintvalidation/#toc-safari

这篇关于HTML5 for HTML5必填字段设置为在Safari中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆