[英]How to remove white space on several of urls
On a page with several urls I want to be able to remove the whitespace in the slug and replace it with a hyphen. 在一个有几个网址的页面上,我希望能够删除slug中的空白并用连字符替换它。 I can case where I have a single url, but I'm having trouble with multiple url case.
我可以说我有一个网址,但我遇到多个网址的问题。 I assume the script must use
each(function())
Based on the version I used for the single version I tried the following: 我假设脚本必须使用
each(function())
基于我用于单个版本的版本,我尝试了以下内容:
$(document).ready.(function() {
$('a.testlink').each(function() {
var Text = $(this);
Text = Text.toLowerCase();
Text = Text.replace(/[\s]+/g,'-');
$(this).attr("href", Text);
});
});
But the script fails completely having no effect on the url - it neither makes lower case nor replaces the whitespace. 但是脚本完全没有对url产生任何影响 - 它既不会使小写也不会替换空格。
How do I get the script to loop over each href and replace any spaces found in the slug. 如何让脚本循环遍历每个href并替换slug中找到的任何空格。
I believe the line that says var Text = $(this);
我相信
var Text = $(this);
should be var Text = $(this).attr("href");
应该是
var Text = $(this).attr("href");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.