Code代码片断(5do8)

AJAX特效框架库基础语法

新主题
js设置css的定位
正则获取图片地址,链接地...
生成一个友好的url地址
XHTML的模板文件
使文本框自动完成功能无效...
从路径中获取文件名
说话自由

首页 » JavaScript » 基础语法 »

生成一个友好的url地址

标签: regexp

<script type="text/javascript">

    // Store the current title value
    var title = 'This is a title with a symbol &'

    // alert(title); // debug

    // Clean up the title        
    var url = title
        .toLowerCase() // change everything to lowercase
        .replace(/^\s+|\s+$/g, "") // trim leading and trailing spaces        
        .replace(/[_|\s]+/g, "-") // change all spaces and underscores to a hyphen
        .replace(/[^a-z0-9-]+/g, "") // remove all non-alphanumeric characters except the hyphen
        .replace(/[-]+/g, "-") // replace multiple instances of the hyphen with a single instance
        .replace(/^-+|-+$/g, "") // trim leading and trailing hyphens                
        ; 
    
    alert(url); // outputs 'this-is-a-title-with-a-symbol'

</script>



但是中文就没了。。。

ccdot写于2008-7-4 19:03:42

如果愿意,请留下你观点或者感受...
称呼*
内容*
验证码*