我正在尝试在WordPress contact form 7中制作报价请求联系人表单。现在,我的网站中有多个不同的部门,可以为其提出报价请求。我希望他们都能引导到相同的网站,以减少工作等。
现在,人们可以在5个不同的复选框中选择他们想要报价的部门。对于每个部门,我需要问两个具体问题,以便自己更容易报价,但这些问题应该只在复选框被勾选时才会出现。我已经使用以下命令完成了此操作:
function myFunction() {
// Get the checkbox
var checkBox = document.getElementById("Propulsion and Stabilization");
// Get the output text
var text = document.getElementById("text");
// If the checkbox is checked, display the output text
if (checkBox.checked == true){
text.style.display = "block";
} else {
text.style.display = "none";
}
}
这是我在联系人表单中使用的,它将显示“船长度”和一个文本框,当勾选该框时。
<p id="text" style="display:none"><label> Ship Length
[text text-234]</p> </label>
勾选该框后,“文本”(问题)将完全显示出来。现在我的问题是,我如何使问题看起来是“必填”的,以便人们填写?我试着正常地在document.getElementById(“text”)后面添加required;但是由于某些原因,我不能让它工作。有什么想法吗?
发布于 2020-07-12 17:12:03
遗憾的是,我还没能让它正常工作。我已经尝试了这个的多个变体:
function myFunction() {
// Get the checkbox
var checkBox = document.getElementById("Propulsion and Stabilization");
// Get the output text
var text = document.getElementById("text");
// If the checkbox is checked, display the output text
if (checkBox.checked == true){
text.style.display = "block";
text.setAttribute("required", "");}
else {
text.style.display = "none";
element.removeAttribute("required");}
}
但这并不管用。
https://stackoverflow.com/questions/62821415
复制相似问题