本文介绍了多步骤形式的必填属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用了多步骤表单,并且在某些输入字段中使用了"required"属性.就这样
I have used a multistep form and I am using "required" attribute in some of the input fields. As such
<input type="text" placeholder="Full name" id="name" name="name" required="Please enter your full name">
用户填写一张表单,然后单击下一步,然后单击三下即可提交.
The user fills one form and clicks next and after three nexts he can submit.
但是必填属性仅在我单击提交按钮时触发.我希望用户在单击表单的下一个之前填写所有字段.我的意思是,必填项必须在下一个按钮上触发.
But the required attribute triggers only when the I click the submit button.I want the user to fill all the fields before he clicks next on the form. By that I mean that the required must trigger on the next button.
推荐答案
您可以运行一个函数来检查输入字段是否为空,然后将必需的属性添加到输入元素中.
You can run an function to check if the input field is empty, then add the required attribute to the input element.
示例代码:
function checkValue() {
var name = document.getElementById("name");
if(name.value === "") {
var att = document.createAttribute("required");
name.setAttributeNode(att);
}
}
<form>
<input type="text" placeholder="Full name" id="name" name="name">
<button onclick = "checkValue()">Next</button>
</form>
希望这会有所帮助!
这篇关于多步骤形式的必填属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!