html li标签使用javascript按内容隐藏 [英] html li tags hide by content using javascript

查看:103
本文介绍了html li标签使用javascript按内容隐藏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计





我试图写一个用户脚本(用于Greasemonkey Firefox),它会隐藏某些Listentries(

 <   li  >  

)因为它的内容。



示例:

 <   ul      =  list  >  
< li > < a href = / name1 / > [...] < / li >
< ; li > < a href = / name3 / > [...] < / li >
< li > < a href = / name2 / > [...] < / li >
< / ul >





内容 - nameX - 每次加载网页时都会有不同的顺序。

我希望用户脚本用某个nameX隐藏li将列在清单上,例如



name3

name4

name7

name8



这样,上面的代码将显示name1和name2之间的差距。

有人可以给我一些指示如何实现这是通过JavaScript吗?



我想过使用jQuery:

 $('  ul.list li a [href = nameX]')。parent() .hide(); 



没有让它工作。

无论如何,我可以为黑名单创建一个数组而不是nameX吗?





顺便说一句,之前有一个类似的问题,但我不能使用这个解决方案,因为与OP的情况不同,这个位置总是会改变:http://www.codeproject.com/Questions/331500/html-li-tags-hide-使用-javascript





抱歉我的英文不好 - 我希望你仍然能理解我想说的话。

非常感谢你阅读和回答!

解决方案

' ul.list li a [href = nameX]')。parent()。hide();



没有让它工作。

无论如何,我可以为黑名单创建一个数组而不是nameX吗?





顺便说一句,之前有一个类似的问题,但我不能使用这个解决方案,因为与OP的情况不同,这个位置总是会改变:http://www.codeproject.com/Questions/331500/html-li-tags-hide-使用-javascript





抱歉我的英文不好 - 我希望你仍然能理解我想说的话。

非常感谢您阅读和回答!


使用CSS来阻止显示。然后你可以使用jquery在必要时取消隐藏。







 <   html  >  
< head >
< title > hidden li的< / title >

< style 类型 = text / css >

li ħ ide { display none; }


< / style >


< / head >
< body >


< ul >
< li > 我没有隐藏< ; / li >
< li class = 隐藏 > 我隐藏< ; / li >
< li > 我没有隐藏< / li >
< / ul >

< br / > 上面有3个li,但只有2个可见。


< / body >
< / html >


Hey Guys


Im trying to write an userscript (for Greasemonkey Firefox) which will hide certain Listentries (

<li>

) because of its content.

Example:

<ul class="list">
<li>   <a href="/name1/" > [...] </li>
<li>   <a href="/name3/" > [...] </li>
<li>   <a href="/name2/" > [...] </li>
</ul>



The content - nameX - will be in a different order each time the webpage is loaded.
I want the userscript to hide li with certain nameX which will be on a list, like

name3
name4
name7
name8

this way the code above will be displayed with a gap between name1 and name2.
Can someone give me some pointers how to achieve this via JavaScript?

I thought about using jQuery:

$('ul.list li a[href=nameX]').parent().hide();


didn't get it to work tho.
anyways, could I create an array instead of the nameX for the "blacklist"?


btw, a similiar question was asked before, but I cant use this solution because the position will always change unlike in the case of the OP: http://www.codeproject.com/Questions/331500/html-li-tags-hide-using-javascript


Sorry for my bad english - I hope you could still understand what I was trying to say.
Thank you very much for reading and possibly answering!

解决方案

('ul.list li a[href=nameX]').parent().hide();


didn't get it to work tho.
anyways, could I create an array instead of the nameX for the "blacklist"?


btw, a similiar question was asked before, but I cant use this solution because the position will always change unlike in the case of the OP: http://www.codeproject.com/Questions/331500/html-li-tags-hide-using-javascript


Sorry for my bad english - I hope you could still understand what I was trying to say.
Thank you very much for reading and possibly answering!


Use CSS to prevent display. Then you can use jquery to unhide if necessary.



<html>
<head>
<title>the hidden li's</title>

<style type="text/css">

li.hide { display:none; }


</style>


</head>
<body>


<ul>
<li>i'm not hidden</li>
<li class="hide">I'm hidden</li>
<li>I'm not hidden</li>
</ul>

<br />There are 3 li's above but only 2 are visible.


</body>
</html>


这篇关于html li标签使用javascript按内容隐藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆