没有表单需要html5输入类型。它工作吗? [英] html5 input type required without a form. Does it work?

查看:129
本文介绍了没有表单需要html5输入类型。它工作吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用:HTML 5必需。

I want to use: HTML 5 Required.

,例如

<input type='text' required>

如果输入类型在表单中,它似乎只能工作。
我可以不单独使用它然后通过javascript调用某种验证第一种方法吗?

it only seems to work if the input type is in a form. Can I not use it on its own and then by javascript call some sort of validate first method ?

更多评论反馈:

我有

    <input id='name' type='text' required>
    <input id='surname' type='text' required>
    <input id='send' type='button' onclick ='send()'>

    function send() {
       if (document.getElementById('name').value == '') { alert('missing name'); return }
       if (document.getElementById('surname').value == '') { alert('missing surname'); return }

       // logic now...

    }

检查输入参数的位,并通过使用HTML 5发送我想要改变的警告

The bit where it checks the input params and sends alert that's the bit I would like to change by using HTML 5

推荐答案

当然,使用

document.getElementById('your_input_id').validity.valid

动态检查字段的有效性。

to check validity of field dynamically.

这篇关于没有表单需要html5输入类型。它工作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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