1

現在、スペースを削除してハイフンに置き換えるには、次の方法があります。スペースをハイフンに置き換え、ドットを何も置き換えずに同じ変数に保持するにはどうすればよいですか?

url = url.replace(/\s/g, '-');
4

2 に答える 2

3

url = url.replace(/\s/g, '-').replace(/\./g, '');するかもしれません。

于 2012-10-07T11:42:47.160 に答える
2

私はこれを使用します:

// This little gadget does replace for all not just first occurence like the native javascript function.
String.prototype.replaceAll = function(strTarget, strSubString){
  var strText = this;
  var intIndexOfMatch = strText.indexOf(strTarget);
  while (intIndexOfMatch != -1){
    strText = strText.replace(strTarget, strSubString);
    intIndexOfMatch = strText.indexOf(strTarget);
  }
  return(strText);
}
于 2012-10-07T11:43:55.980 に答える