更换匹配的文本我有这样的诗句缩写列表:PHP:与查询字符串
Mt=80
Lu=81
Rv=92
Nd=95
etc.
我目前jQuery来将这些链接:
<a href="page.php?q=Mt 5: 2">Mt 5: 2</a>
<a href="page.php?q=Mt 5: 2">Nd 14: 25</a>
,使它们如下:
<a href="page.php?book=Mt&chapter=5&vmin=2">Mt 5: 2</a>
<a href="page.php?book=Nd&chapter=15&vmin=25">Nd 14: 25</a>
脚本用来即:
$(document).ready(function() {
$("a[href='page.php']").each(function(index, element){
href = $(element).attr('href'); // get the href
text = $(element).text().split(' '); // get the text and split it with space
$(element).attr('href', href + "?book=" +$.trim(text[0])+"&chapter="+$.trim(text[1].slice(0,-1))+"&vmin="+$.trim(text[2])); //create desired href and replace it with older-one
});
});
我所需要的是> <
之间的文本转换为适当数量(MT = 80,陆= 81,RV = 92,N D = 95 ..等),使转换后的链接变得像:
<a href="page.php?book=80&chapter=5&vmin=2">Mt 5: 2</a>
<a href="page.php?book=95&chapter=15&vmin=25">Nd 14: 25</a>
为什么'14:25'被转换成'&章= 15&VMIN = 25' ? (为什么'14:'变成'chapter = 15'? – Justinas
感谢您的回复..只是分别.. trim()用于删除多余的空格,如果该值有任何(前导/尾随空格)和slice()用于删除:从第二个值开始 - 所以第一个是这本书,第二个是章节,第三个是vmin – Mike
@Mike HE正在谈论'Nd 14: 25'这里'chapter = 15'需要'chapter = 14' –