[英]How can I edit checkout page with javascript?
我試圖在選擇單選按鈕時使結帳頁面成為更改字段。 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. 當第二個單選按鈕被選中時,反之亦然。
我在這個網站上主要使用 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";
}
}
我在 header 中有這個代碼作為腳本。 我不確定它是否不正確,或者我沒有代碼來調用這個 function。 Id 和 class 名稱如下:
單選按鈕 id:radio-5984531736 選擇 A 時應顯示的信息 class 名稱:fizica 選擇 A 時應顯示的信息 class 名稱:司法
我做了一個類似於你的任務的演示:
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>
雖然我認為在你的情況下它可以更簡單。 例如,嘗試編寫this['radio-5984531736']
而不是this.radio-5984531736
。 此外,您不需要function yesnoCheck() {...
中的 'radio-5984531736'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.