两个按钮验证的html5必需属性 [英] html5 required attribute on two buttons validation

查看:54
本文介绍了两个按钮验证的html5必需属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI,



在一个页面上我有两组不同的输入,我想使用html5必需属性进行验证。





第一张表格是注册表格,它应该验证控制权的注册。第二种形式是订阅时事通讯,它应该验证具有所需属性的电子邮件。我有两个按钮用于注册,另一个用于新闻订阅。个人都很好,但当我把它们放在同一个表格上并点击注册按钮时,它也会验证通讯文本框,请填写此字段。



i希望当我点击新闻信提交按钮时,只有它应该要求发送电子邮件,当我点击注册表时,它应该要求添加注册的控件。



有人可以帮帮我吗?



on one page i have two different set of inputs that i want to validate using html5 required attribute.


first form is registration form and it should validate control for registration. second form is for newsletter subscribe it should validate email with required attribute. i have two button one for registration and other for news subscription. individual both works good but when i put them on same form and click on register button it also validate newsletter text box by saying please fill out this field.

i want that when i click on news letter submit button then only it should ask for email and when i click on register form it should ask for controls which are added for registration.

can some please help me ?

推荐答案

不知道,这个建议是否有效,但是一旦你点击不需要它的按钮就尝试删除验证
No idea, if this suggestion will work or not, but try removing the validations once you click the button where its not requried


我做的是我在JavaScript端创建两个函数并删除相应按钮的每个客户端点击事件所需的属性。





ie



what i did is i create two function on JavaScript side and remove required attribute on each client click event of respective buttons.


i.e

function onregisterbuttonclick ()
{
document.GetElementById('txtreg').required = true;
document.GetElementById('txtnewsletter').required = false;
}


function onnewsletterbuttonclick ()
{
document.GetElementById('txtreg').required = false;
document.GetElementById('txtnewsletter').required = true;
}


这篇关于两个按钮验证的html5必需属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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