我有一个带有单选按钮的表格。 我想将值复制到弹出窗口。
您可以在此处查看代码示例: https://codepen.io/quardonmedia/pen/yrOGJq
因此,如果选中了Radio 1,它将复制该操作,同时还会在弹出窗口中选中Radio 1。
尝试使用/添加此代码(仅一个收音机的示例):
<button id="myBtn" onClick="copy()">Open Modal</button>
function copy() {
var areaA = document.getElementById("upplus_v");
var areaB = document.getElementById("upplus");
var valueA = areaA.value;
areaB.value = valueA;
}
HTML:
<form class="straksberegning" method="post" id="formid" action="">
<p>
<input type="radio" class="form-radio" name="product" id="upplus_v" value="5">
<label for="upplus" class="upgrade_container">Radio 1</label>
</p>
<p>
<input type="radio" class="form-radio" name="product" id="uppremium_v" value="13" checked>
<label for="uppremium" class="upgrade_container">Radio 2</label>
</p>
</form>
<button id="myBtn">Open Modal</button>
<!--popup-->
<div id="myModal" class="modal">
<div class="modal-content">
<span class="close">×</span>
<form class="straksberegning" method="post" id="formid" action="">
<p>
<input type="radio" class="form-radio" name="product" id="upplus" value="5">
<label for="upplus" class="upgrade_container">Radio 1</label>
</p>
<p>
<input type="radio" class="form-radio" name="product" id="uppremium" value="13" checked>
<label for="uppremium" class="upgrade_container">Radio 2</label>
</p>
<input name="cta_order_calc_upgrade" type="submit" class="" value="OPGRADÉR" id="submitthis"/>
</form>
</div>
</div>
用于弹出窗口的JS:
var modal = document.getElementById('myModal');
var btn = document.getElementById("myBtn");
var span = document.getElementsByClassName("close")[0];
btn.onclick = function() {
modal.style.display = "block";
}
span.onclick = function() {
modal.style.display = "none";
}
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}