如何用jquery中的其他文本/符号替换文本/符号 [英] how to replace text/symbol with other text/symbol in jquery

查看:69
本文介绍了如何用jquery中的其他文本/符号替换文本/符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有一个asp.net网站,



在我的jquery代码中,我正在更换这个



 getData ={~Ref~:〜+ sp [0] +〜,〜参考〜 :〜+ sp [1] +〜,〜描述〜:〜+ sp [2] +〜,〜数量〜:〜+ sp [3] +〜,〜单位〜:〜+ sp [4] +〜,~UnitPrice~:〜+ sp [5] +〜,~TotalPrice~:〜+ sp [6] +〜},; 


//// alert(getData);

var fullData =[+ getData.replace(/'/ g,'\')。replace('〜','')+];





并在'fulldata'中替换,实际上并没有用单引号替换所有'〜'

但它只替换了第一个'〜'。



任何人都可以帮助我。





谢谢

解决方案

你需要使用一个正则表达式,并将global标志设置为第一个参数 - 就像你做了第一次替换电话:

  var  fullData =   [ + getData.replace(/ '  / g,' \  ')。replace(/〜/ g,' ' )+];  


Hi guys,

I have an asp.net website,

in my jquery code, i'm replacing this

getData = "{~Ref~:~" + sp[0] + "~,~Reference~:~" + sp[1] + "~,~Description~:~" + sp[2] + "~,~Quantity~:~" + sp[3] + "~,~Unit~:~" + sp[4] + "~,~UnitPrice~:~" + sp[5] + "~,~TotalPrice~:~" + sp[6] + "~},";


////alert(getData);

var fullData = "[" + getData.replace(/'/g, '\"').replace('~', '"') + "]";



and replace in 'fulldata', is not actually replacing all '~' with single quotes
but its replacing the ever first '~' only.

can any one please help me.


Thanks

解决方案

You need to use a regular expression with the "global" flag set as the first parameter - just as you did for the first replace call:

var fullData = "[" + getData.replace(/'/g, '\"').replace(/~/g, '"') + "]";


这篇关于如何用jquery中的其他文本/符号替换文本/符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆