Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在变量中使用Jquery.not()_Javascript_Jquery_Function - Fatal编程技术网

Javascript 在变量中使用Jquery.not()

Javascript 在变量中使用Jquery.not(),javascript,jquery,function,Javascript,Jquery,Function,可能重复: 我有以下功能: function initCBox(){ CB_Init(); var img1 = $(select.currentImg).attr('src'); var label = $(select.currentImg).attr('alt'); var desc = $('.item.active .caption').not($('.description')).text(); CB_Open('href=' +

可能重复:

我有以下功能:

function initCBox(){
    CB_Init(); 
    var img1 = $(select.currentImg).attr('src');
    var label = $(select.currentImg).attr('alt');
    var desc = $('.item.active .caption').not($('.description')).text();    

    CB_Open('href=' + img1 + ',,title=' + label + ',,comment=' + desc +'');     
}
使用以下html:

<div class="item" title="Light" href="Light.jpg" >
   <img class="content" alt="Amber Light" src="slides/Light.jpg"/>
<div class="caption">Light
<ul class="icon"> 
      <li class="ui-state-default ui-corner-all" title="More Info">
          <div class="description ui-icon ui-icon-comment">
          <div class="description_holder"  style="display:none">Amber Light
          <br />Enter Text or HTML Here</div>
          </div> </li> 
    </ul>
</div></div>

轻的
  • 琥珀色灯
    在此处输入文本或HTML

我希望我的var=desc只显示类“caption”中的文本,而不是
中的任何内容(为简单起见,我只包括一个
  • 项,但在
    中有其他项)。需要我排除标题文本以外的所有内容的帮助。希望我没有太困惑

    您可以执行字符串查找和替换:

    var desc = $('.caption').text(), // The caption and stuff you don't want
        noWant = $('.icon').text();  // Only stuff you don't want
    desc = desc.replace(noWant,"");  // Find stuff you don't want and replace w ""
    

    这样做的好处是,即使包含
    s、
    s等,它也能抓住描述的全部文本。

    为什么不将标题文本放在带有类或id的
    span
    中呢?因为我用于图像库的javascript、ContentFlow、,使用带有类标题的div,并且我的jqueryui图标需要在此div中(标题下)为库中的每个图像显示。感谢链接Felix,它似乎对我的特定问题起到了作用。尽管您不一定要排除所有子体(如可能的副本)。例如,您希望在此处包含
    我的标题