[英]How can I edit checkout page with javascript?
I am trying to make the checkout page a change fields when a radio button is selected.我试图在选择单选按钮时使结帐页面成为更改字段。 So I have 2 options on the radio buttons option A and B When A is selected I want 2 fields below to remain available and other 2 to disappear.
So I have 2 options on the radio buttons option A and B When A is selected I want 2 fields below to remain available and other 2 to disappear. The other way around when the second radio button is checked.
当第二个单选按钮被选中时,反之亦然。
I mostly used Wordpress for this website but I need a bit of code for this functionality.我在这个网站上主要使用 Wordpress,但我需要一些代码来实现这个功能。
function yesnoCheck('radio-5984531736') {
if (this.radio-5984531736 == "Persoana fizica") {
alert("check");
document.getElementByClassName("juridica").style.display = "block";
} else {
document.getElementByClassName("fizica").style.display = "none";
}
}
I have this code as script in the header.我在 header 中有这个代码作为脚本。 I am not sure if it is not correct or I don t have a code to call this function.
我不确定它是否不正确,或者我没有代码来调用这个 function。 The Id and class names are the following:
Id 和 class 名称如下:
Radio buttons id: radio-5984531736 Info that should show when A selected class name: fizica Info that should show when A selected class name: juridical单选按钮 id:radio-5984531736 选择 A 时应显示的信息 class 名称:fizica 选择 A 时应显示的信息 class 名称:司法
I've made a demo similar to your task:我做了一个类似于你的任务的演示:
function yesnoCheck() { var value = document.querySelector("[name='radio-5984531736']:checked").value; if (value === "v1") { document.querySelector(".fizica").style.display = "block"; document.querySelector(".juridica").style.display = "none"; } else { document.querySelector(".fizica").style.display = "none"; document.querySelector(".juridica").style.display = "block"; } } var form = document.querySelector("#formId"); form.addEventListener("change", yesnoCheck);
<div> <form id="formId"> <div> <input type="radio" name="radio-5984531736" value="v1" id="v1id"> <label for="v1id">Persona fizica</label> <input type="radio" name="radio-5984531736" value="v2" id="v2id"> <label for="v2id">Persona juridica</label> </div> <div class="fizica"> Prenume <input name="prenume"><br/> Nume companie <input name="numecom"> </div> <div class="juridica"> Nume <input name="nume"><br/> CUI <input name="cui"> </form> </div>
Though I think it can be simpler in your case.虽然我认为在你的情况下它可以更简单。 Eg try writing
this['radio-5984531736']
instead of this.radio-5984531736
.例如,尝试编写
this['radio-5984531736']
而不是this.radio-5984531736
。 Also, you don't need 'radio-5984531736' in function yesnoCheck() {...
.此外,您不需要
function yesnoCheck() {...
中的 'radio-5984531736'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.