我不知道这是否可行,但我有一个页面有2个问题和2个单选按钮(是和否)。
只有一个'是'可以选择单选按钮,然后预先选择' No'另一个问题的单选按钮。这是使用JavaScript并且工作正常。
我的问题是,如果用户选择“是”&#39;问题和我的隐藏部分会显示,用户输入一个条目并点击“添加”按钮。按钮,这会填充我的表格,但如果用户则选择“否”&#39;到了&#39;是&#39;重新隐藏我的<div>
(这是正确的)的问题,但如果他们再选择“是”&#39;对于另一个问题,该部分被重新显示,<table>
仍然有前一个条目。有没有办法在选择&#39; No&#39;
HTML code:
Template template = new Template();
template.Nvc.Add("[!YesRadioButton]", Html.RadioButton("TransferISA_RadioButton", "Yes", ViewData["TransferISA_Yes"].Equals(true), new { id = "TranYes", onclick = "CheckRadioOptions(this,'TransferIsa_Cell','No');", onchange = "oneSelection()", title = "To select 'Yes', 'No' has to be selected for a Child Trust Fund transfer in." }).ToHtmlString());
template.Nvc.Add("[!NoRadioButton]", Html.RadioButton("TransferISA_RadioButton", "No", ViewData["TransferISA_No"].Equals(true), new { id = "TranNo", onclick = "CheckRadioOptions(this,'TransferIsa_Cell','No');", onchange = "oneSelection()" }).ToHtmlString());
template.Nvc.Add("[!TranErrorMsg]", (Html.ValidationMessage("TransferISA_RadioButton") != null) ? Html.ValidationMessage("TransferISA_RadioButton").ToHtmlString() : "");
template.HtmlTemplate = cmsText.Text;
if (app.IsChild)
{
template.Nvc.Add("[!CTFYesRadioButton]", Html.RadioButton("CTF_RadioButton", "Yes", ViewData["CTF_Yes"].Equals(true), new { id = "CTFYes", onclick = "CheckRadioOptions(this,'TransferIsa_Cell','No');", onchange = "oneSelection()", title = "To select 'Yes', 'No' has to be selected for a Junior ISA transfer in." }).ToHtmlString());
template.Nvc.Add("[!CTFNoRadioButton]", Html.RadioButton("CTF_RadioButton", "No", ViewData["CTF_No"].Equals(true), new { id = "CTFNo", onclick = "CheckRadioOptions(this,'TransferIsa_Cell','No');", onchange = "oneSelection()" }).ToHtmlString());
template.Nvc.Add("[!CTFErrorMsg]", (Html.ValidationMessage("CTF_RadioButton") != null) ? Html.ValidationMessage("CTF_RadioButton").ToHtmlString() : "");
template.HtmlTemplate = cmsText.Info_Text;
}
JavaScript的:
function CheckRadioOptions(obj, layers, showValue) {
if (obj == document.getElementById("CTFYes"))
{
document.getElementById("Transfer").style.display = "none";
document.getElementById("CTF").style.display = "block";
}
else
{
document.getElementById("Transfer").style.display = "block";
document.getElementById("CTF").style.display = "none";
}
if (obj != null) {
var value = "";
for (var i = 0; i < obj.length; i++) { if (obj[i].checked) { value = obj[i].value; } }
if (value == "") { value = obj.value; }
if (value == showValue) { HideLayers(layers); } else { ShowLayers(layers); }
}
}
function oneSelection() {
if (document.getElementById("TranYes").checked == true) {
document.getElementById("CTFYes").disabled = true;
document.getElementById("CTFNo").checked = true;
}
if (document.getElementById("CTFYes").checked == true) {
document.getElementById("TranYes").disabled = true;
document.getElementById("TranNo").checked = true;
}
if (document.getElementById("TranNo").checked == true) {
document.getElementById("CTFYes").disabled = false;
}
if (document.getElementById("CTFNo").checked == true) {
document.getElementById("TranYes").disabled = false;
}
}
我还没有为隐藏的<div>
添加我的HTML,因为它有大量的,但是下面是显示隐藏<div>
的整页,并填充了表格。
答案 0 :(得分:0)
需要在我的代码中添加此内容
app.Application.Products.IsaDetails.IsaTransfers.Clear();