2010-09-26 13 views

回答

1

使用str.replace(/\(/g,'').replace(/\)/g,'');

3

你可以使用正則表達式,或者

<html> 
<body> 

<script type="text/javascript"> 

var str="(abc, def)"; 
document.write(str.replace("(","").replace(")","")); 

</script> 
</body> 
</html> 
+0

這種方法實際上是安全更清潔即使給定要替換的元素實際上並不存在於字符串中,也會導致replace()的鏈接工作得很好。 (即使字符串中不存在「(」或「)」) – CoffeeSipper 2016-03-31 07:29:17

0

使用單一的替代版本正則表達式是str.replace(/\(|\)/g,"");

相關問題