如何使用jQuery从字符串中删除特殊字符

时间:2014-03-07 09:58:12

标签: jquery

我有一个像这样的字符串

{
    "\"test\":\"Connect_Disconnect\",\"os\":\"Windows NT\",\"report\":\"Verify Wireless Interface present and state is Disconnected:OK
Verify Profile not present on the Client:OK
Add Profile to the Client:OK
Verify Profile Added Present on the Client:OK
Connecting to Access Point:OK
Verify the State is Connected:OK
Disconnecting from Access Point:OK
Verify the State is Disconnected:OK
Delete Profile to the Client:OK
Verify Profile Not Present on the Client:OK
\"": ""
}

如何使用jQuery删除特殊字符并获取如下所示的输出:

test:Connect_Disconnect,os:Windows NT,report:Verify Wireless Interface present and state is Disconnected:OK
Verify Profile not present on the Client:OK
Add Profile to the Client:OK
Verify Profile Added Present on the Client:OK
Connecting to Access Point:OK
Verify the State is Connected:OK
Disconnecting from Access Point:OK
Verify the State is Disconnected:OK
Delete Profile to the Client:OK
Verify Profile Not Present on the Client:OK

2 个答案:

答案 0 :(得分:0)

试试这个

var product= $("#product").val().replace(/[^a-z0-9\s]/gi, '').replace(/[_\s]/g, ' ')

答案 1 :(得分:0)

请尝试在javascript

中替换功能
  var val='"\"test\":\"Connect_Disconnect\",\"os\":\"Windows NT\",\"report\":\"Verify Wireless Interface present and state is Disconnected:OK Verify Profile not present on the Client:OK Add Profile to the Client:OK Verify Profile Added Present on the Client:OK Connecting to Access Point:OK Verify the State is Connected:OK Disconnecting from Access Point:OK Verify the State is Disconnected:OK Delete Profile to the Client:OK Verify Profile Not Present on the Client:OK \"": ""';

        val=val.replace(/"/g,'');
        val=val.replace(/\\/g,'');