【发布时间】:2018-12-15 16:35:37
【问题描述】:
我正在寻找一种解决方案,以便在页面加载时从我的 html 中删除项目。
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Модули <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="#"><strong>blabla</strong></a>
</li>
<li>
<a href="/admin/logentry/">blabla6</a>
</li>
<li role="presentation" class="divider"></li>
<li>
<a href="#"><strong>blabla5</strong></a>
</li>
<li>
<a href="/entrances/apartment/">blabla4</a>
</li>
<li>
<a href="/entrances/entrance/">blabla3</a>
</li>
<li>
<a href="/entrances/entrancekasasummary/">blabla2</a>
</li>
<li>
<a href="/entrances/paymentscashier/">blabl1</a>
</li>
</ul>
</li>
所以我想删除例如 blabla4、blabla2、blabla1,包括它们的 <li> 标签
这是我迄今为止尝试过的
<script type="text/javascript">
// select relevant elements
var elements = $('content-main');
// go through the elements and find the one with the value
elements.each(function(index, domElement) {
var $element = $(domElement);
// does the element have the text we're looking for?
if ($element.text() === "blabla2") {
$element.hide(); // hide the element with jQuery return false;
// jump out of the each
}
});
</script>
【问题讨论】:
-
告诉我们你的尝试,否则没有人会帮助你。
-
这是我迄今为止尝试过的
<script type="text/javascript"> // select relevant elements var elements = $('content-main'); // go through the elements and find the one with the value elements.each(function(index, domElement) { var $element = $(domElement); // does the element have the text we're looking for? if ($element.text() === "blabla2") { $element.hide(); // hide the element with jQuery return false; // jump out of the each } }); </script> -
您的问题得到解答了吗?如果是这样,为什么您还没有选择答案?如果没有,你为什么没有做出相应的评论?
标签: javascript jquery contains