Checkboxlist已启用,设置为false [英] Checkboxlist enabled set to false
问题描述
大家好,
我需要一些帮助.
我有一个包含城市的清单.我想在其中做些什么.
当我从CheckBoxList中选择3个城市时,选择之后,它必须自动禁用其余项目.
意思是:
在CheckBoxList中有5个项目.如果选择了5个项目中的任何3个,则其余2个必须自动被禁用.
您也可以看到此站点.
www.99acres.com(进入高级搜索)
您可以在其中找到此功能.
请一些身体帮助我.
我在编程之间陷入了困境.
Hello guys,
I need some assistance.
I have a checkboxlist having cities. And I want to do something in it.
When I select 3 cities from the CheckBoxList then after selection, it must automatically disable the remaining items.
Means:
In CheckBoxList there are 5 items. If any 3 of the 5 items are selected, then remaining 2 must automatically get disabled.
You can also see this site.
www.99acres.com(go to the advanced search)
There u can find this functionality.
Please some body help me.
I have got stuck in between my programming.
推荐答案
如果选定的项目数达到极限,则可以应用简单的逻辑来使项目disabled
. >
我尝试了,找到了解决方案.看看吧
you can apply a simple logic to make itemsdisabled
if selected item count reach to a limit.
I tried and I found a solution. have a look on it
<script language="javascript" type="text/javascript">
function disableAfterSelecton(ctrl) {
var disableItemsAfetrSelection = ctrl.getAttribute('maxSelectedCount', 0);
var inputRefArray = ctrl.getElementsByTagName('input');
if (getSelectedCount(ctrl) == disableItemsAfetrSelection) {
//checking if the selected item count reached to the limit, then disbled remaining
for (i = 0; i < inputRefArray.length; i++) {
if (!inputRefArray[i].checked) makeItemEnableDisable(inputRefArray[i], false);
}
}
else if (getSelectedCount(ctrl) < disableItemsAfetrSelection) {
//checking if the selected item count is below the limit then again enable the remaining items
for (i = 0; i < inputRefArray.length; i++) {
if (!inputRefArray[i].checked) makeItemEnableDisable(inputRefArray[i], true);
}
}
}
// function to retun the selected items count
function getSelectedCount(ctrl) {
var inputRefArray = ctrl.getElementsByTagName('input');
var checkedCount = 0;
for (i = 0; i < inputRefArray.length; i++) {
if (inputRefArray[i].checked) ++checkedCount;
}
return checkedCount;
}
function makeItemEnableDisable(item, isEnabled) {
if (!isEnabled)
item.disabled = 'disabled';
else
item.disabled = '';
}
</script>
这是CheckBoxList代码
here is the CheckBoxList code
<asp:CheckBoxList ID="chkItems" runat="server" maxSelectedCount="3" onclick="return disableAfterSelecton(this);">
maxSelectedCount
是您可以根据需要决定的自定义属性.这是我的主意,可以使代码看起来更好.
谢谢
Here maxSelectedCount
is the custom property which you can decide based on your requirement. This is my idea, you can make the code looks better.
Thanks
您好,
据我所知,Disabled
属性代表整个复选框列表,而不代表其项目.
这意味着您不能禁用复选框列表的某些项目;您只能禁用整个控件.
问候.
Hi,
As far as I know, theDisabled
property stands for the whole checkboxlist, not for its items.
This means you cannot disable some items of the checkboxlist ; you can only disable the whole control.
Regards.
我认为您可能需要使用
manage_optionlist
复选框调用的javascript函数进行某些操作.如果您查看页面的源代码,则会发现该复选框的以下代码,
javascript function called by checkbox. If you view the source of the page you would find following code for the checkbox,
Select Upto 5 Property Types</span></label><div class="lf scrollbox" id=''proptype_scroll''><input name="property_type[]" type="checkbox" id="Residential Apartment" value="1" class="chbx" onclick="return manage_optionlist(''|proptype'');">
我在源代码中找不到该函数,但是我想它已经在站点的某个位置声明了,您需要找到它.
:)
I couldn''t find the function in the source code but I would guess it has been declared somewhere in the site, you would need to find that.
:)
这篇关于Checkboxlist已启用,设置为false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!