且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

HTML5表单验证的条件规则

更新时间:2022-05-20 09:17:48

我不认为你可以在没有javascript的情况下做到这一点。

I don't think you can do this without javascript.

使用javascript,你可以很容易地做到这一点。

With javascript, you could do this easily enough.

我会添加 required 仅在单击复选框后才归属。

I would add the required attribute only after the checkbox is clicked.

事实上,我会将其设为切换件,这样用户就可以取消选中并取消输入。

In fact, I would make this a toggled piece, so that the user can uncheck and unrequire the input.

但是,我不会依赖浏览器执行所需的属性。相反,我会使用一些CSS创建我自己的必需通知(突出显示,动画,显示一些单词)。

However, I would not rely on browser's implementation of the required attribute. Instead, I would create my own required notification using some CSS (highlighting, animation, displaying some words).