jquery: auto-create url from title
i'm looking for jQuery code which will suggest me a URL for new CMS article, based on the Title of article.
E开发者_开发问答xample:
I wrote title: The sky is blue
jQuery autogenerated URL: /the-sky-is-blue/
function slugify(str){
return str.replace(/\s+/g,'-').replace(/[^a-zA-Z0-9\-]/g,'').toLowerCase();
}
var mySlug = slugify("testing the slugify function"); // testing-the-slugify-function
One way without jquery:
var title = text.replace(/\s+/g, '-').toLowerCase();
精彩评论