问题描述
这是两个checbox,当检查它是否不能正常播放我的div时可以使用,但是如果不检查则不可以.我不知道该如何解决...
我有taht这样的代码
It two checbox, it is work when check it is dysplay my div , but if uncheck it doesn''t. I don''t know how i fix this...
I have my code like taht
<table>
<pre lang="xml"><tr>
<td>
Run</td>
<td>
<input type="checkbox" ID="chkrun" runat="server" class="check" value="Y" onclick="OptionTwo(this)" />
</td>
</tr>
<tr>
<td >
walk</td>
<td>
<input type="checkbox" ID="chkwalk" runat="server" class="check" value="Y" onclick="OptionOne(this)"/>
</td>
</tr>
<pre lang="msil">function selectOptionTwo(switchElement){
if (switchElement.value == ''Y'') {
document.getElementById("SchedulePickup").style.display = "none";
}
{
document.getElementById("SchedulePickup").style.display = ''block'';
}
}
<script type="text/javascript">
function OptionOne(Element){
if (switchElement.value == ''Y'') {
document.getElementById("div").style.display = "block";
}
else
{
document.getElementById("div").style.display = "none";
}
}
function OptionTwo(Element){
if (switchElement.value == ''Y'') {
document.getElementById("div").style.display = "none";
}
}
</script>
推荐答案
function OptionOne(Element){
if (Element.value == 'Y') {
document.getElementById("div").style.display = "block";
}else {
document.getElementById("div").style.display = "none";
}
}
其次,您可以使用CheckBox的checked属性而不是value属性.
它会在您选中和取消选中时自动显示,否则必须像Chris提到的那样设置Y和N值.
希望这会有所帮助.
-***********************
评论2-
嗨
我只是说/建议,请将此代码复制粘贴到html文件中,然后在任何浏览器上运行
然后重新考虑您的需求...在此html页面上进行测试..
Secondly you can use CheckBox''s checked property rather than value property.
it would automatically as you check and uncheck , else you have to set value Y and N as you check as Chris mentioned.
Hope this helps.
-***********************
Comment 2 -
Hi
I would just say/suggest please copy paste this code to a html file and run this on any browser
and then start over to think what you need...do the testing on this html page..
<html>
<body>
<script type = "text/javascript">
function CheckOne(ele) {
if (ele.checked) {
document.getElementById("div1").style.display = 'none';
}else {
document.getElementById("div1").style.display = 'block';
}
}
</script>
<div id = "div1">
<input type = "text"> Hello </input>
</div>
<input type = "checkbox" id = "checkbox1" onClick="CheckOne(this);"/>
</body>
</html>
谢谢
Thanks
这篇关于Javascript仅使用两个复选框,一个取消选中又选中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!