开发者

jquery: auto-create url from title

开发者 https://www.devze.com 2023-01-25 05:29 出处:网络
i\'m looking for jQuery code which will suggest me a URL for new CMS article, based on the Title of article.

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();
0

精彩评论

暂无评论...
验证码 换一张
取 消