Skip to content

Instantly share code, notes, and snippets.

@leizongmin
Created September 18, 2012 09:38
Show Gist options
  • Save leizongmin/3742269 to your computer and use it in GitHub Desktop.
Save leizongmin/3742269 to your computer and use it in GitHub Desktop.
根据标题生成URL函数
/**
* 生成用于title的URL
*
* @param {string} title
* @return {string}
*/
function titleUrl (title) {
if (typeof(title) !== 'string') return false;
return title.trim().replace(/[^0-9a-zA-Z \-]/g, '').replace(/[ ]+/g, '-').replace(/[\-]+/g, '-').toLowerCase();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment