繁体   English   中英

jQuery的选择<a>标签,其中包含嵌套的div中特定的href</a>

[英]jquery Select <a> tag which contains specific href in nested div

如何使用jquery在以下代码中选择包含href="www.dummy.ch"<a>标记。

我必须使用_top而不是_blank修改target属性。 标签中未设置ID或类属性。

谢谢,帕特里克

 <div class="QvContent" style="width: 485px; height: 26px; overflow: visible; border-bottom-right-radius: 1px; border-bottom-left-radius: 1px; background-color: rgba(255, 255, 255, 1);"> <div class="QvGrid" style="width: 485px; height: 26px; overflow: hidden; font-family: Tahoma; font-size: 8pt; font-style: normal; font-weight: normal; text-decoration: none; position: relative; cursor: default;" incontainer="false" fixed_cols_left="1"> <a style="position: absolute;" href="http://www.dummy.ch" target="_blank" unselectable="on"> <div title="URL " style="left: 0px; top: 0px; width: 389px; height: 13px; text-align: center; color: rgb(54, 54, 54); overflow: hidden; font-style: normal; font-weight: normal; text-decoration: underline; position: absolute; cursor: pointer; background-color: rgba(255, 255, 255, 1);"> <div style="left: 0px; top: 0px; width: 389px; height: 13px; border-left-color: rgba(220, 220, 220, 1); border-left-width: 0px; border-left-style: solid; position: absolute;" unselectable="on"/> <div class=" injected" style="padding: 0px 2px; width: 385px; height: 13px;"> <div title="URL " style="width: 385px; overflow: hidden; white-space: pre; cursor: default; -ms-word-wrap: normal;" unselectable="on"> <a style="display: inline-block;" href="http://www.axeed.ch" target="_blank" unselectable="on">URL</a> </div> </div> </div> </a> </div> </div> 

尝试

$("a[href*='www.dummy.ch']").attr("target", "_top");

试试看:您可以使用包含 jquery 选择器属性来获取具有href值且包含www.dummy.ch的所有锚,并更改其目标值。

$("a[href*='www.dummy.ch']").attr("target", "_top");

如果您想要域,则加上子域: $("a[href*='dummy.ch']").attr("target", "_top");

如果您想要的域没有子域: $("a[href*='//dummy.ch']").attr("target", "_top");

如果要定位特定协议: $("a[href^='http://dummy.ch']").attr("target", "_top"); (用“ http”代替)。

* =部分表明href属性包含dummy.ch ^ =部分表示href标记以引号内的内容开头。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM