Javascript 如何在列表视图上循环(客户端禁用中的特定复选框)
我有这样一个列表视图:Javascript 如何在列表视图上循环(客户端禁用中的特定复选框),javascript,jquery,asp.net,Javascript,Jquery,Asp.net,我有这样一个列表视图: <telerik:RadListView ID="rlv_available_sys" runat="server" ItemPlaceholderID="sys_holder" DataKeyNames="process_id" OnItemDataBound="rlv_available_sys_ItemDataBound"> &
<telerik:RadListView ID="rlv_available_sys" runat="server" ItemPlaceholderID="sys_holder"
DataKeyNames="process_id" OnItemDataBound="rlv_available_sys_ItemDataBound">
<ItemTemplate>
<table>
<colgroup>
<col title="process name" />
</colgroup>
<tr>
<td>
<asp:HiddenField ID="hf_id" runat="server" Value='<%#Eval("process_id")%>' />
<asp:CheckBox ID="chb_sys" runat="server" CausesValidation="false" />
<asp:Label ID="lbl_available_sys" runat="server" Text='<%# Eval("process_name") %>'></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
</telerik:RadListView>
).mousedown(函数(e){
e、 停止传播();
})。单击(函数(){
如果(确认('此小部件将被删除,是否确定?')){
$(此).parents(settings.widgetSelector).animate({
不透明度:0
},函数(){
$(this).wrap(“”).parent().slideUp(函数(){
$(this.remove();
});
});
}
返回false;
}).appendTo($(settings.handleSelector,this));
}
我想做的是:
当用户单击close以删除小部件时,使用jquery方法禁用预期的复选框并设置checked=true。(如何在客户端修改以前的jquery以执行此操作)我假设
设置。widgetSelector
选择小部件的顶部元素,即表格或其周围的Telerik包装。我保留您的其他代码不变:
...
if(confirm('This widget will be removed, ok?')) {
// reference to current widget wrapper
var widget = $(this).parents(settings.widgetSelector);
// disable and select (all) contained checkboxes
widget.find('input[type=checkbox]').prop({disabled: true, checked: true});
// animate and remove widget...
widget.animate({
opacity: 0
...
请注意,此解决方案将禁用并选择小部件中包含的所有复选框。如果您有多个复选框,并且只需要选择一个复选框,请为其指定一个类(例如,myCheckbox
),然后将选择器更改为
widget.find('input[type=checkbox].myCheckbox').attr({disabled: true, checked: true});
如果有多个小部件,则不应使用现有的复选框ID,因为元素ID对于整个文档应该是唯一的
更新:
原来我误解了这个问题:要禁用的复选框不在所提到的小部件中,实际任务是
…如果输入类型=“隐藏”的值等于li(小部件)的id,则禁用输入类型=“复选框”
(见评论中的讨论。)
这可能是一个解决方案:
...
$(settings.widgetSelector, $(settings.columns)).each(function () {
var widgetId = this.id;
var thisWidgetSettings = iNettuts.getWidgetSettings(widgetId);
if (thisWidgetSettings.removable) {
$('<a href="#" class="remove">CLOSE</a>').mousedown(function (e) {
e.stopPropagation();
}).click(function () {
if(confirm('This widget will be removed, ok?')) {
// Disable checkboxes which have a sibling hidden input field with value equal to widgetId
$('table tr input[type=hidden]').filter(function() {
return $(this).val() == widgetId;
}).siblings('input[type=checkbox]').prop({disabled:true, checked: true});
// animate and remove widget...
$(this).parents(settings.widgetSelector).animate({
opacity: 0
...
。。。
$(settings.widgetSelector,$(settings.columns))。每个(函数(){
var widgetId=this.id;
var thisWidgetSettings=iNettuts.getWidgetSettings(widgetId);
如果(thisWidgetSettings.removable){
$('').mousedown(函数(e){
e、 停止传播();
})。单击(函数(){
如果(确认('此小部件将被删除,是否确定?')){
//禁用具有值等于widgetId的同级隐藏输入字段的复选框
$('表tr输入[type=hidden]')。过滤器(函数(){
返回$(this.val()) == widgetId;
}).sides('input[type=checkbox]')).prop({disabled:true,checked:true});
//动画和删除小部件。。。
$(此).parents(settings.widgetSelector).animate({
不透明度:0
...
Hm,我猜这里发生了复制粘贴错误。如果您注释掉小部件('input[type=checkbox')).attr({disabled:true,checked:true});代码>行你应该有和以前一样的行为。对不起,我的错:我的答案有一个打字错误(第一个版本中缺少.find
调用。我已通过应答进行了更新…哦,现在我明白了:小部件不是您在代码中的项目?抱歉,这有点误导。您是否可以为每个复选框指定一个单独的ID,如
?这样,您可以通过调用轻松禁用/选择任何复选框。)$(At.ChbySys'`+PesiSeSd).AtTr({禁用:true,Chuest:Trase});< /Cord>。好,我已经更新了我的答案,解决了这个问题,看看。对不起,我不知道你打算用你最后的评论。我的更新解决了你的问题吗?请考虑用新的信息更新你的问题。
...
$(settings.widgetSelector, $(settings.columns)).each(function () {
var widgetId = this.id;
var thisWidgetSettings = iNettuts.getWidgetSettings(widgetId);
if (thisWidgetSettings.removable) {
$('<a href="#" class="remove">CLOSE</a>').mousedown(function (e) {
e.stopPropagation();
}).click(function () {
if(confirm('This widget will be removed, ok?')) {
// Disable checkboxes which have a sibling hidden input field with value equal to widgetId
$('table tr input[type=hidden]').filter(function() {
return $(this).val() == widgetId;
}).siblings('input[type=checkbox]').prop({disabled:true, checked: true});
// animate and remove widget...
$(this).parents(settings.widgetSelector).animate({
opacity: 0
...