【问题标题】:jQuery programatically change font family in a checkboxlistjQuery 以编程方式更改复选框列表中的字体系列
【发布时间】:2017-01-05 09:15:41
【问题描述】:

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

方法(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' });

【问题讨论】:

  • 您是否使用一组固定的字体大小和字体系列?如果是这样,将它们添加为辅助 css 类,然后使用 jquery 切换这些类会更容易,而不是内联所有样式。
  • 不,我只需要加粗所有“myWebItem”,我是 jQuery 的绝对初学者对不起:(

标签: c# jquery html css asp.net


【解决方案1】:

您已将 myWebItem “id”声明为“cbBold_”,请更改 id。

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

【讨论】:

  • @MarcoC 养成接受答案的习惯,如果它解决了您的问题。
猜你喜欢
  • 1970-01-01
  • 2016-11-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-27
  • 2019-03-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多