我试图用JQuery隐藏这个div。
<div id="nbar" style="background-color: #f7f7f7; box-shadow: 0 0 1px lightgray; margin-bottom: 20px; padding-left: 0; width: 100%; margin-top: 5px" class="search-navbar collapse navbar-collapse font-xs">
<ul class="no-margin nav navbar-nav">
<li><a href="#" id="ccb">Computer Code</a></li>
<li><a href="#" id="nameb">Name</a></li>
<li><a href="#" id="experienceb">Experience</a></li>
<li><a href="#" id="winsb">No of Win Cases</a></li>
<li><a href="#" id="totalb">Total Cases</a></li>
<li><a href="#" id="tlsrankb">TLS Rank</a></li>
</ul>
<!---End of no-margin nav navbar-nav--->
</div>
准备就绪
function SearchLawyers(SearchText) {
var url1 = "LawyerData/SearchLawyer/?pTextToSearch=" + SearchText;
MyWebApp.Gl
obals.MakeAjaxCall("GET", url1, "{}", function (result) {
if (result.success === true) {
console.log(result);
window.globala = result.data;
debugger;
if (jQuery.isEmptyObject(window.globala.LawyerList)) {
window.isFind = false;
$("#nbar").css({ 'display': 'none' });
$("#nbar").hide();
$(".no-margin nav navbar-nav").hide();
$("#Records").html("<h1>No Results Found...!!!<h1>");
}
else {
window.isFind = true;
DisplayLawyerData(result.data);
}
} else {
MyWebApp.UI.showRoasterMessage(result.error, Enums.MessageType.Error);
}
}, function (xhr, ajaxOptions, thrownError) {
MyWebApp.UI.showRoasterMessage('A problem has occurred while getting Lawyers: "' + thrownError + '". Please try again.', Enums.MessageType.Error);
});
}
但它不起作用。 jquery成功执行并且没有显示任何错误,但div仍然在页面上。没有找到记录显示但div也可见
答案 0 :(得分:0)
可能您在实际呈现到页面之前隐藏了div
。试试这个
$(document).ready(function () {
$("#nbar").hide();
});
答案 1 :(得分:0)
//in document ready event
$('#nbar').hide();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="nbar" style="background-color: #f7f7f7; box-shadow: 0 0 1px lightgray; margin-bottom: 20px; padding-left: 0; width: 100%; margin-top: 5px" class="search-navbar collapse navbar-collapse font-xs">
<ul class="no-margin nav navbar-nav">
<li><a href="#" id="ccb">Computer Code</a></li>
<li><a href="#" id="nameb">Name</a></li>
<li><a href="#" id="experienceb">Experience</a></li>
<li><a href="#" id="winsb">No of Win Cases</a></li>
<li><a href="#" id="totalb">Total Cases</a></li>
<li><a href="#" id="tlsrankb">TLS Rank</a></li>
</ul>
<!---End of no-margin nav navbar-nav--->
</div>
答案 2 :(得分:0)
Jquery是基于事件的,您需要在某些事件上隐藏,例如在Window load上。
$(document).ready(function(){
$("#nbar").hide();
});
或强>
$(document).ready(function(){
$("#nbar").css({'display':'none'});
});
答案 3 :(得分:0)