我有以下HTML;

<p class="postcontent">
<img src="#">
Some Text
</p>


我希望只能隐藏文本。
到目前为止,我有这个;

  jQuery(function($) {
$(".postcontent").$('[type=text]').hide();
  });


编辑:我没有对html的任何控制,所以我需要通过Jquery添加它。

最佳答案

您可以将文字包装在FLY上,然后将其隐藏:

HTML:

<p class='postcontent'> <a href=#> dsds </a> aaa </p>


Javascript:

$('.postcontent').contents().filter(function() {
     return this.nodeType == 3; })
             .wrap('<label"> <label />').parent().hide();


JSFiddle



根据评论更新:
为什么要创建两个标签?这很容易,因为它有两个文本节点...:

<p class='postcontent'> (!!FirstTextNode!!)
    <a href=#> dsds </a> (!!SecondTextNode!!) aaa
</p>

07-26 06:37