我正在使用Squarespace,所以我试图注入一个代码来与他们现有的代码一起工作。在这个页面上,大约有10个电子邮件地址出现在照片旁边,每张照片和Squarespace生成的电子邮件之间的代码是一致的。我想这样做,当我点击电子邮件地址(或.summary-excerpt)时,一个链接会打开默认的邮件应用程序,比如<a href="mailto:someone@example.com">Send Mail</a>,但我不能只是将代码写到页面上,因为照片是如何使用图库功能对齐的。
首先,我尝试使用Jquery选择电子邮件。这就是我到目前为止所知道的:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<style>
.summary-excerpt:hover{
cursor: pointer;
}
</style>
<script>
$(document).ready(function(){
$(".summary-excerpt").click(function(){
var link_to_email = this.p:nth-of-type(2).html();
window.location.href = link_to_email;
});
});
</script>这是我试图遍历的树:

发布于 2015-12-23 02:50:50
可以将.find与nth-child(index)选择器一起使用
var link_to_email = $(this).find("p:nth-child(2)").text();https://stackoverflow.com/questions/34422514
复制相似问题