删除事件'replace'的文本

You*_*uss 0 javascript jquery replace

我想删除一些text用这段代码说的文字:

$(".jq-text li a").html(function(i, h){
     return h.replace(/text/, "");
  }); 
Run Code Online (Sandbox Code Playgroud)

正如预期的那样,它运作良好.问题是我想删除文本http://,所以我试过:

$(".jq-text li a").html(function(i, h){
     return h.replace(/http:///, "");
  }); 
Run Code Online (Sandbox Code Playgroud)

这在Dreamweaver中给我一个错误......我该怎么写呢?

Fré*_*idi 7

你必须在正则表达式中转义正斜杠:

return h.replace(/http:\/\//, "");
Run Code Online (Sandbox Code Playgroud)


Mut*_*ran 6

你需要逃避/使用\/

尝试,

$(".jq-text li a").html(function(i, h){
     return h.replace(/http:\/\//, "");
  }); 
Run Code Online (Sandbox Code Playgroud)