我想使用标题作为 tumblr 中图片帖子的标题,但如您所知,tumblr 在标题中添加了来源链接。
现在,我可以将标题区域设为负边距,但并非每个帖子都应该有源代码。
有没有办法忽略标题中的源文本/链接(可以用作 JavaScript 字符串)?
谢谢
以下是实例:
使用 {Caption}
产生
- “(来源:[sourcelink],来自 [vialink])”如果没有可用的标题 - 这是需要隐藏/不显示的内容
- “(通过 [vialink])”如果没有可用的来源或标题 - 也需要隐藏
- “[sourcelink]:[caption]”如果标题可用 - 无需隐藏
- “[caption]”(如果您是字幕来源) - 也不应隐藏
最佳答案
我不太了解 Tumblr,但至少你可以在页面中加载 jQuery 并使用正则表达式删除不需要的元素。
此外,您不必将任何边距设置为奇怪的值。
jQuery 看起来像这样:
$('.caption').each(function() {
// Get the html() of the .caption div
var text = $(this).html();
// Look for (Source...) and remove it
var regex = /\(Source:.*via(.*)\)+/ig;
text = text.replace(regex, '');
// Look for (via...) and remove it
regex = /\(via(.*)\)+/ig;
text = text.replace(regex, '');
// Finally set the html() of the .caption div
$(this).html(text);
});
看看这个 JSFiddle 示例:http://jsfiddle.net/jpreynat/atd5erbh/2/
关于javascript - 如何在 tumblr 中使用标题时忽略源文本/链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13213102/