开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜