【发布时间】: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