2016-11-05 80 views
2

我需要使用jQuery字符串HTML附加到DOM中的DOM:添加HTML來使用jQuery

我有這樣的HTML字符串:

var html = "<div id="inspectorMenu" style="display: none;">"+ 
      "<label id="showInspectorName" style="padding: 13px 09px; color:white"></label>"+ 
      "<ul id="" class="nav pull-left">"+ 
      "<li style="display: inline-block;text-align: center; max-height:35px;"><a class="navbar-brand" ui-sref="sites.list" style="padding: 11px 09px;" title="אתרים"><i class="glyphicon glyphicon-tree-conifer"></i></a></li>"+ 
      "<li style="display: inline-block;text-align: center;max-height:35px;"><a class="navbar-brand" ui-sref="sitesDamages.sitesList" style="padding: 11px 09px;" title="אירועים"><i class="glyphicon glyphicon-exclamation-sign"></i></a></li>"+ 
      "</ul>"+ 
      "</div>" 

而且我有這樣的HTML代碼:

<div class="navbar-header"> 
     <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> 
      <span class="icon-bar"></span> 
      <span class="icon-bar"></span> 
      <span class="icon-bar"></span> 
     </button> 
     @Html.ActionLink("sites maintaice", "Index", "Dashboard", new { area = "" }, new { @class = "navbar-brand" }) 

    //===========I need to add html string here!!!==============// 

    </div> 

使用jQuery我需要在</div>標記和@Html.ActionLink之間添加html字符串。

任何想法如何實現它?

+0

讓您的導航欄頭的ID,然後做的document.getElementById(id)的.innerHTML + = yourHTML; ? – NavkarJ

回答

2

要通過@Html.ActionLink生成的標記後插入HTML,在DIV結束後,可以追加

$(".navbar-header").append(html); 
+0

謝謝你的回答。如果我需要刪除某些時候添加的html,該怎麼辦? – Michael

+0

@Michael你應該將id添加到該元素(對該html),然後 '$('#thatGivenId')。remove()'或$('#thatGivenId')。hide() – rakaz