0

I have this problem: I have a javascript, saved in a database field, that is going to be used in a web page as a href target, e.g.

insert into table_with_links (id, url) 
       values (1, 'javascript:var url="blö blö";.....');

// run scripts that use the database values to generate web pages

// part of the generated html code:
<a href="javascript:var url='blabla';..... </a>

So far no problems. I have german letters (Umlaute - e.g. ö) in the javascript. I shouldn't save the german letters in the database, so I escape them:

insert into table_with_links (id, url) 
       values (1, 'javascript:var url="bl%F6 bl%F6";.....');

Now comes the problem - I shouldn't store the % sign in the database either, because the scripts that generate the web pages cannot handle it properly. I guess you can imagine how these scripts are 3-rd party scripts and cannot be changed.

So, my question is - can I also escape the % sign?

4

2 回答 2

2

你试过这个吗?:

var str= "remove the %";
var str_n = str.replace("%",""); 

这里是基础http://www.w3schools.com/jsref/jsref_replace.asp

然后你可以使用一个字符数组来替换看看这里javascript replace global with array

于 2012-11-21T16:03:27.110 回答
1

我建议使用 oracle 的内置国际化功能,Oracle 能够处理特殊的德语字符:

http://docs.oracle.com/cd/B19306_01/appdev.102/b14258/u_i18n.htm

如果您想自己处理它,我建议对您知道的某个序列进行字符串替换:

var str = str.replace(/ö/g,"[german-umlaute]");

(/ö/g 末尾的 g 是替换字符串中所有出现的地方)

于 2012-11-21T16:06:19.970 回答