<a href="/symptoms/treat-your-childs-headache/">
<span class="read-more-button">Read More</span>
</a>
我在视图源代码中有上面的代码,并且有多个具有相同名称的按钮&#34; Read More&#34;没有身份证。
一旦用户点击任何阅读的更多链接/按钮,我想让href名称带有管道分隔符。
例如:在上面的示例中,如果用户点击了更多内容,我希望将值设为
Read More | /symptoms/treat-your-childs-headache/
完全陌生的编码和尝试学习。请帮助。我想使用jQuery。
答案 0 :(得分:1)
使用.one()
.read-more-button
元素添加点击事件监听器
$(function() {
$('.read-more-button').one('click', function() {
// append the href
$(this).append(' | ' + $(this).parent().attr('href'));
// don't follow the link
return false;
});
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="/symptoms/treat-your-childs-headache/">
<span class="read-more-button">Read More</span>
</a>
&#13;