2016-11-05 2 views
2

を使用してDOMにHTMLを追加:私はjQueryのを使用して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

、その後のdocument.getElementById(id)を行い、あなたのナビゲーションバー、ヘッダーにIDを付け.innerHTML +を追加することができ、@Html.ActionLinkによって生成されるマークアップの後にHTMLを挿入するには= yourHTML; ? – NavkarJ

答えて

2

DIVの終わりに、あなたは

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

ありがとうございました。追加されたhtmlをある時点で削除する必要がある場合はどうすればよいですか? – Michael

+0

@Michaelあなたはその要素(そのhtml)にidを追加し、次に '$( '#thatGivenId')。remove()または$( '#thatGivenId')。 – rakaz

関連する問題