两个按钮验证的html5必需属性

两个按钮验证的html5必需属性

本文介绍了两个按钮验证的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 ?

推荐答案


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必需属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 17:09