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.