问题描述
我想获取h1标题文本并将其添加到mailto的主题行.我已经做到了这一点.我只是不知道如何用正确的表达方式替换用标题替换".克隆会朝正确的方向发展吗?感谢您的关注!
I want to grab the h1 headline text and add it to the subject line of mailto. I got as far as this. I just don't know how to substitute 'replace this with the headline' with the correct expression. Would clone be in the right direction? Thanks for taking a look!
<h1>Headline</h1>
<div id="mailme"><a href="mailto:[email protected]?subject=">Email Link</a></div>
$('#mailme a').each(function() {
$(this).attr('href', $(this).attr('href') + 'replace this with the h1 headline');
});
感谢所有提出解决方案的人.我已经在一个简单的HTML页面模板中使用了该模板,客户端正在编辑内容,但没有HTML技能.每个内容页面都有一个电子邮件按钮,该按钮使用以下脚本之一根据页面标题来自定义电子邮件主题行.我希望其他人也会发现它有用.
Thanks to everyone that pitched in solutions. I have used it in a simple HTML page template where the client is editing content but has no HTML skill. Each content page has a email button which uses one of the scripts below to customize the email subject line depending on the page headline. I hope others will find this useful too.
推荐答案
$('#mailme a').each(function() {
$(this).attr('href', $(this).attr('href') + $('h1').text());
});
这应该有效.
如果您有多个h1
标签(如biko所指出的),则以下方法将起作用
If you have multiple h1
tags (as pointed out by biko) the following will work
$('#mailme a').each(function() {
$(this).attr('href', $(this).attr('href') + $(this).closest('#mailme').prev('h1').text());
});
这篇关于如何使用jquery将HTML标题文本复制/克隆到href mailto主题行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!