首页 > 代码库 > asp.net后台代码访问前台html标签

asp.net后台代码访问前台html标签

//单击按钮后批量改变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";      }  
Code
//单击按钮后批量改变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";          }      }  
Code
//单击按钮后批量改变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;  
Code

 

asp.net后台代码访问前台html标签