jQuery以编程方式更改checkboxlist中的字体系列

时间:2017-01-05 09:15:42

标签: c# jquery html css asp.net

我想改变某些"元素的字体系列"在复选框列表中,我尝试使用此代码,但它不起作用:

方法(atm我在后面的代码中更改了文本颜色和字体系列,但我想用jQuery来做):

private void bindCheckBoxList()
        {
            using (SPWeb web = new SPSite(SPContext.Current.Site.Url).OpenWeb())
            {
                foreach (SPWeb currentWeb in web.Site.AllWebs)
                {
                    string webTitle = currentWeb.Title;

                ListItem myWebItem = new ListItem();
                myWebItem.Text = webTitle;
                myWebItem.Value = currentWeb.Url;
                myWebItem.Attributes.Add("id", "cbBold_" + webTitle);
                myWebItem.Attributes.Add("style", "color: red; font-weight: bold");
                CbList.Items.Add(myWebItem);

                foreach (SPList currentList in currentWeb.Lists)
                {
                    string listTitle = currentList.Title;

                    ListItem myListItem = new ListItem();
                    myListItem.Text = listTitle;
                    myListItem.Value = web.Url + ";" + currentList.Title;
                    myListItem.Attributes.Add("id", "cb_" + listTitle);

                    CbList.Items.Add(myListItem);

                    if (currentList.BaseType == SPBaseType.DocumentLibrary)
                    {
                        myListItem.Text = listTitle + "(Document Library)";
                    }
                    else
                    {
                        myListItem.Text = listTitle + "(List)";
                    }
                }
            }
        }
    }

HTML:

<asp:CheckBoxList ID="CbList" runat="Server" OnSelectedIndexChanged="CbList_SelectedIndexChanged" BulletStyle="NotSet" ClientIDMode="Static">
</asp:CheckBoxList>

jQuery的:

 $("[id^=CbBold]").css({ 'font-weight': 'bold' });

1 个答案:

答案 0 :(得分:2)

您已声明myWebItem&#34; id&#34; as&#34; cbBold _&#34;,改变身份。

$("[id^=cbBold_]").css({ 'font-weight': 'bold' });