![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
//单击按钮后批量改变li元素的内联文本值及样式 for (int i = 1; i <= 8; i++) { HtmlGenericControl li = this.FindControl("li" + i) as HtmlGenericControl; li.InnerHtml = "新值" + i.ToString(); li.Attributes.CssStyle.Value = "color:red"; }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
//单击按钮后批量改变li元素的内联文本值及样式 foreach (Control control in ul1.Controls) { if (control is HtmlGenericControl) { HtmlGenericControl li = control as HtmlGenericControl; li.InnerHtml = "新值" + (counter++).ToString(); li.Attributes.CssStyle.Value = "color:red"; } }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
//单击按钮后批量改变li元素的内联文本值及样式 HtmlDocument htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(ul1.InnerHtml); HtmlNodeCollection lis = htmlDoc.DocumentNode.SelectNodes("li"); for (int i = 0; i < lis.Count; i++) { lis[i].InnerHtml = "新值" + (i + 1).ToString(); lis[i].Attributes.Add("style", "color:red"); } ul1.InnerHtml = htmlDoc.DocumentNode.InnerHtml;