根据从MSSQL数据库C#检索到的数值在div中动态创建glyphicon星

我正在从数据库中获取一个评分(可能大于5),并且我想根据页面加载时收到的值来创建glyphicon星。有关用于检索值的代码,请参见下文。


int rating_count = DBinteract.get_rating_count(ticket_id);

我试图根据检索到的值循环遍历并将glyphicons添加到div中,但是在页面加载时仅显示一个星星。


for (int i = 0; i < rating_count; i++)

  {

    this.rating_count.InnerHtml="<span class='glyphicon glyphicon-star'></span>";

  }

我正在尝试向中添加星号的div


  <td>

         <div id="rating_count" runat="server"></div>

  </td>


UYOU
浏览 142回答 1
1回答

繁花不似锦

您需要将字符串彼此追加,以span在生成的字符串中获得多个字符串html,否则,您将string多次分配相同的字符串.InnerHtml。而且,如果您还没有这样做,请记住需要将.innerHtml需求初始化为第empty string一个:this.rating_count.InnerHtml = "";for (int i = 0; i < rating_count; i++){&nbsp; &nbsp; this.rating_count.InnerHtml += "<span class='glyphicon glyphicon-star'></span>";&nbsp; &nbsp; //&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;look here: ^^}但是,如果有Javascript支持,可以使用String.repeat()完成此任务:int rating_count = DBinteract.get_rating_count(ticket_id);this.rating_count.InnerHtml = "<span class='glyphicon glyphicon-star'></span>".repeat(rating_count);
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript