问题描述
我试图点击一个复选框,这样我就可以看到一个隐藏的文本框,我试过放一个脚本但它似乎没有工作,当我取消选中复选框时,文本框不会隐藏
这就是我所做的..
Im trying to click on a checkbox so that i can see a hidden textbox, i have tried putting a script but it doesnt seem to be working, The textbox doesn't hide when i uncheck the checkbox
This is what i did..
<script type="text/javascript">
function ShowHideDiv(chkSymptom)
{
var dvSymptom = document.getElementById("dvSymptom");
dvSymptom.style.display = chkSymptom? "block" : "none";
}
</script>
我在文本框中引用了脚本以自动隐藏
and I referenced the script on the textbox to autohide
< input type =checkboxid = chkSymptomonclick =ShowHideDiv(this)/>
@ Html.Label(Symptoms Identif?,new {@class =control-label col-md-2})
<input type="checkbox" id="chkSymptom" onclick="ShowHideDiv(this)"/>
@Html.Label("Symptoms Identified?", new {@class = "control-label col-md-2"})
@ Html.EditorFor(model => model.Symptoms,new {htmlAttributes = new {@class =form-control,id =txtPassportNumber,@ placeholder =Symptoms Identified}})
@ Html.ValidationMessageFor(model = > model.Symptoms,,new {@clas s =text-danger})
@Html.EditorFor(model => model.Symptoms, new {htmlAttributes = new {@class = "form-control", id = "txtPassportNumber", @placeholder = "Symptoms Identified"}})
@Html.ValidationMessageFor(model => model.Symptoms, "", new {@class = "text-danger"})
请帮助,如果我从那里遗漏任何东西。
Please help if im missing anything from there.
推荐答案
<script type="text/javascript">
function ShowHideDiv(chkSymptom) {
var dvPassport = document.getElementById("dvPassport");
dvPassport.style.display = chkSymptom.checked ? "block" : "none";
}
和你的文本框参考将是
< input type =checkboxid =chkSymptomonclick =ShowHideDiv(this)/>
@ Html.Label(Symptoms Identified?:)
and on your textbox reference would be
<input type="checkbox" id="chkSymptom" onclick="ShowHideDiv(this)" />
@Html.Label("Symptoms Identified?:")
这篇关于单击复选框时如何自动隐藏和显示文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!