HTML 输入必需属性不适用于字段 [英] HTML input required attribute not working for a field

查看:28
本文介绍了HTML 输入必需属性不适用于字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试进行一些客户端验证,当我将 required 属性添加到我的 HTML 输入时,但它仅适用于某些字段.

I am trying to do some client side validations and when I am adding the required attribute to my HTML inputs but it works only for some fields.

<input type = "text" name="description" id = "descriptionOfChange" required> //this works
<input type = "text" name = "cid" id = "cid" required> //this does not work(also is my primary key. Not sure if that is the reason why)
<input type="text" name = "dateOfCompletion" id="datepicker" required /> //this works too

推荐答案

它应该可以正常工作,但只是为了确保,试试这个:

It should work fine as it is, but just to make sure, try this:

<input type = "text" name = "description" id = "descriptionOfChange" required /> 
<input type = "text" name = "cid" id = "cid_css" required /> 
<input type = "text" name = "dateOfCompletion" id = "datepicker" required />

虽然,半关闭这个标签不是必须的,但它会使一些浏览器的行为变得怪异,尤其是 IE.

Although, semiclosing this tag is not necessary, it can make some browsers behave in a weird way, especially IE.

这篇关于HTML 输入必需属性不适用于字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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