需要JavaScript来启用或禁用该复选框 [英] Need a javascript to enable or disable the check box
问题描述
大家好我有我的GridView的两个检查框控件我需要的是,如果我选中复选框其他应得到允许,如果我取消它应该得到禁止有没有办法做到这一点。
我写这篇文章,但我没有得到所需的1
<脚本类型=文/ JavaScript的>
功能checkboxClick(选中,boxId){
VAR childCheckbox =的document.getElementById(boxId);
!childCheckbox.disabled =检查; 如果(childCheckbox.disabled)禁用时//取消
childCheckbox.checked = FALSE;
}
< / SCRIPT> < ASP:复选框ID =CheckBox1=服务器的OnClientClick =checkboxClick(this.checked); />
< ASP:复选框ID =boxId=服务器启用=FALSE/>< / DIV>
基本上,你要的是这样的:
函数checkboxClick(选中){
的document.getElementById('childCheckbox')禁用=检查。!;
}<输入类型=复选框的onclick =checkboxClick(this.checked); />
<输入类型=复选框ID =childCheckbox/>
现在,如果他们是ASP.NET控件,< ASP:复选框/>
,你可能会想修改 checkboxClick
,这样它也需要复选框的客户端ID启用/禁用。
< ASP:复选框=服务器ID =CB1/>
< ASP:复选框=服务器ID =CB2/>变种CB2 =的FindControl(CB2);
((复选框)的FindControl(CB1))的OnClientClick =checkboxClick(this.checked,'+ cb2.ClientID +');;
修改
容纳进一步要求每个注释:
函数checkboxClick(选中,boxId){
VAR childCheckbox =的document.getElementById(boxId);
!childCheckbox.disabled =检查; 如果(childCheckbox.disabled)禁用时//取消
childCheckbox.checked = FALSE;
}< ASP:复选框=服务器ID =CB1/>
< ASP:复选框=服务器ID =CB2启用=FALSE/> <! - 禁用负载 - >
Hi all i am having two check box controls in my gridview what i need is if i checked a check box the other should be get enabled and if i uncheck it should get disable is there any way to do it.
I write this but i am not getting the required one
<script type="text/javascript">
function checkboxClick(checked, boxId) {
var childCheckbox = document.getElementById(boxId);
childCheckbox.disabled = !checked;
if(childCheckbox.disabled) //uncheck when disabled
childCheckbox.checked = false;
}
</script>
<asp:CheckBox ID="CheckBox1" runat="server" OnClientClick ="checkboxClick(this.checked);" />
<asp:CheckBox ID="boxId" runat="server" Enabled="false" /></div>
Basically, what you want is something like this:
function checkboxClick(checked) {
document.getElementById('childCheckbox').disabled = !checked;
}
<input type="checkbox" onclick="checkboxClick(this.checked);" />
<input type="checkbox" id="childCheckbox" />
Now, if they're ASP.NET controls, <asp:CheckBox />
, you will probably want to edit checkboxClick
so that it also takes the ClientID of the checkbox to enable/disable.
<asp:CheckBox runat="server" id="cb1" />
<asp:CheckBox runat="server" id="cb2" />
var cb2 = FindControl("cb2");
((CheckBox) FindControl("cb1")).OnClientClick = "checkboxClick(this.checked, '" + cb2.ClientID + "');";
EDIT
Accommodating further requirements as per comments:
function checkboxClick(checked, boxId) {
var childCheckbox = document.getElementById(boxId);
childCheckbox.disabled = !checked;
if(childCheckbox.disabled) //uncheck when disabled
childCheckbox.checked = false;
}
<asp:CheckBox runat="server" id="cb1" />
<asp:CheckBox runat="server" id="cb2" Enabled="false" /> <!-- disable on load -->
这篇关于需要JavaScript来启用或禁用该复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!