2011-12-13 40 views
1

我正在修改系统中的标准webcontrol,该系统中有一些字符串值,我无权访问。我想知道是否有一种方法将附加单词附加到字符串中,在任何地方使用jQuery。将字添加到字符串中的任何位置

示例:
当前字符串:您当前正在以这些设置访问这些设置用户名

我想什么:您正在访问这些设置和系统控件用户名

和系统控制是附加的话,我想追加到字符串。这怎么可能通过jQuery?

+3

这是jQuery的更多工作。看看你的JavaScript手册中的字符串操作函数。 – macjohn

回答

3

你不需要的jQuery为,简单的JavaScript就足够了:

var myString = 'You are currently accessing these settings as Username.'; 
var newString = myString.replace ('these settings', 'these settings and system controls'); 

你所使用这里是.replace()方法。

1

延长上月的回答是:

$("#control").text(function (i, text) { 
    return text.replace ('these settings', 'these settings and system controls'); 
}); 
+0

谢谢你。 +1 – diceler

1

也许你需要更多的东西一样吗? 这是Jan的更新回答

var cunstructVar = ' these settings '+' and system controls '+' ... '; 
var originalString = 'You are currently accessing _TO_REPLACE_ as Username.'; 

var newString = originalString.replace ('_TO_REPLACE_', cunstructVar ); 
+0

很好的例子。我的问题是我没有访问提供这些字符串的文件,所以我必须通过javascript修改它们。所以这样做是不可能的,但是对于这个例子,我需要+1这个例子 – diceler

+0

我知道这是因为当我把cunstructVar变成了一个由javascript构建的变种,这就是为什么我把concat ;-) – user1040899

+0

啊我的坏。抱歉 – diceler

相关问题