当我加载页面时,#navbarUsername保持为空。这下面的所有其他脚本运行正常。 我也试过$(document).on('ready','#navbarUsername',function(){... 它不起作用。
JS:
$('#navbar-placeholder').load("navbar.html");
$(document).ready(function () {
$('#navbar-placeholder').on('ready', function () {
$('#navbarUsername').append(UserInfo.Name + " " + UserInfo.Surname + "(" + UserInfo.UserUsername + ")");
});
});
HMTL:
<div id="navbar-placeholder"></div>
和已加载的navbar.html:
<nav id="navbar" class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li class="nav-item">
<a class="nav-link" id="navbarUsername"></a><----HERE--->
</li>
<li class="navbar-item">
<a class="nav-link" style="cursor:pointer;" id="logout" >Log Out</a>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>