2012-07-25 85 views
3

我的innerHTML找到一个CheckBoxList的一个特定的复选框的ASP.NET CheckBoxList的:在jQuery的ASP.NET通过复选框标签

<asp:CheckBoxList ID="CheckBoxList1" runat="server" Width="10%"> 
    <asp:ListItem Selected="True" Value="1">White</asp:ListItem> 
    <asp:ListItem Selected="False" Value="2">Black</asp:ListItem> 
    <asp:ListItem Value="3">Red</asp:ListItem> 
    <asp:ListItem Value="4">Green</asp:ListItem> 
    <asp:ListItem Value="5">Blue</asp:ListItem> 
</asp:CheckBoxList> 

我需要修改/删除特定CheckBox的特定标签一个CheckBoxList的:

下面的代码为CheckBox值做工精细,但它是不工作的复选框标签。

var CheckBoxListInputValue = 3; //value may be dynamic 
var CheckBoxListInputInnerHTML = "Red"; //value may be dynamic 
$("#CheckBoxList1 label[innerHTML =" + CheckBoxListInputInnerHTML + "]").remove(); //Not working 
$("#CheckBoxList1 :input[value = " + CheckBoxListInputValue + "]").remove(); //Working 

顺便说一句,我不想​​使用任何for循环。

回答

0

您可以使用:contains选择:

$("#CheckBoxList1 label:contains(" + CheckBoxListInputInnerHTML + ")").remove(); 

请注意:input选择是弃用,您可以使用input代替。

+0

感谢您的回答。 – user1438964 2012-07-26 07:00:17

1

asp.net从您的CheckBoxList生成的表,以删除您必须实际删除TR的选项。下面的代码删除您的来样红选项,那么你可以与动态值改为红色

$('#CheckBoxList1 label').each(function() { 
     if ($(this).text() == 'Red') { 
      $(this).closest('tr').remove(); 
      return false; 
     } 
    }); 

Test it here