gpt4 book ai didi

jQuery anchor 标记文本重写项目

转载 作者:行者123 更新时间:2023-12-01 07:25:59 24 4
gpt4 key购买 nike

我有一个 WordPress 站点,它列出了目录中的文件。代码被吐出为

<a href="http://helpdesk-3/acme/wp-content/uploads/important_documents/compliance_documents/sample_document.pdf">sample_document.pdf</a>

我正在尝试使用 jQuery 将链接显示文本重写为驼峰式大小写、无扩展名和空格。所以它会运行并将其重写为

<a href="http://helpdesk-3/acme/wp-content/uploads/important_documents/compliance_documents/sample_document.pdf">Sample Document</a>

有人有建议吗?

最佳答案

$('a').each(function() { // Loop over all links
var txt = $(this).text().split('.'); // Link contents, split on '.'
txt.pop(); // remove last (the extension)
txt = txt.join('.').replace(/_/g, ' '); // replace '_' with spaces
txt = $.map(txt.split(' '), function(v) { // split on spaces
// and uppercase the 1st letter
return v.substring(0, 1).toUpperCase() + v.substring(1, v.length);
}).join(' ');
$(this).text(txt); // set the new text
});​

演示:http://jsfiddle.net/f6x9P/1/

关于jQuery anchor 标记文本重写项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9591186/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com