如何不打开重复的链接

时间:2015-02-11 16:34:30

标签: javascript jquery

以下是我尝试打开仪表板内所有管道的代码

function() 
{ 
     jQuery("a[href*='pipelines.cgi?pipelines=']").each(function (index, a) {
     window.open(a.href, '_blank'); }); 
}
)();

这是HTML

  <tr>
    <td width="30px">20150131</td>
    <td width="470px">

        <a href="pipelines.cgi?pipelines=AGS-PART5&dates=20150131">AGS-PART5</a>

            (
        <a title="View jobs upstream of this pipeline" href="pipelines.cgi?pipelines=AGS-PART5&dates=20150131&action=view-upstream">↑</a>
            )
</td>
<td width="15px">
<td>
<td width="280px">
</tr>
        <tr>
        <td width="30px">20150131</td>
        <td width="470px"><a href="pipelines.cgi?pipelines=FBA-MARKETING&dates=20150131">FBA-MARKETING</a>
        (
        <a title="View jobs upstream of this pipeline" href="pipelines.cgi?pipelines=FBA-MARKETING&dates=20150131&action=view-upstream">↑</a>
        )
        </td>
<td width="15px">
<td>
<td width="280px">
</tr>

所以问题是我不想打开“查看此管道上游的作业”,但它包含相同的选择器

编辑: 谢谢David Hughes的代码。只有一件事要排除。

    <b> 
<a href="pipelines.cgi?pipelines=FBA-WBR&dates=20150207&action=view-dashboard&arg1=‌​last_week"> See how this Dashboard looked at this time last week</a>
 </b>

1 个答案:

答案 0 :(得分:1)

您可以使用not()过滤选择以忽略具有title属性的链接:

function() 
 { 
 jQuery("a[href*='pipelines.cgi?pipelines=']").not("[title]").each(function (index, a) {
 window.open(a.href, '_blank'); }); 
 }
 )();