[英]How do you hide an element in JQuery when posting data to .html?
I have a bootstrap navbar and I do a search within a modal. 我有一个引导导航栏,并且在模态中进行搜索。 Everything works fine, except when I do that search it wants to load the navbar into the modal.
一切工作正常,除非我进行搜索时希望将导航栏加载到模式中。
I just want to hide the navbar or prevent it from loading. 我只想隐藏导航栏或阻止其加载。 So I created a
.hide3
class. 所以我创建了一个
.hide3
类。 I was hoping the .not()
JQuery function would stop it from loading, but I must be missing something. 我曾希望
.not()
JQuery函数可以阻止它加载,但是我一定会丢失一些东西。
$("#submit_search").click(function(){
var searchID= btn.data('mylink');
$.post("search.php?&searchID="+searchID,function(data) {
$('#search_results_div').html(data).not('.hide3');
// I also tried $('.hide3').hide(); here but it hides the main navbar and not the new one created.
});
});
<nav class="navbar navbar-inverse navbar-fixed-top hide3" role="navigation">
// content here
$.post("search.php?&searchID="+searchID,function(data) {
$(data).find(".hide3").remove();
$('#search_results_div').html(data);
});
OR assuming there is never a nav bar to be shown inside the search result div 或假设搜索结果div中永远不会显示导航栏
CSS: CSS:
#search_result_div .hide3 { display:none }
OR PHP: 或PHP:
if (!isset($_POST["searchID"])) { ?>
<nav class="navbar navbar-inverse navbar-fixed-top hide3" role="navigation">
<?PHP } ?>
I suppose data contains HTML and the navbar you want to hide is in the data. 我想数据包含HTML,而您要隐藏的导航栏位于数据中。 First use jquery to remove navbar from data and then set it.
首先使用jquery从数据中删除导航栏,然后进行设置。
var $html = $(data);
$html.find('.hide3').hide(); //personally I prefer add a class which hides the content using CSS
$('#search_results_div').html($html);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.