开发者

Replace inside a list of strings with jquery

I've got a list with strings in my script and I want to replace a value inside every string that has that value.

btnEdit.bind("click", function () {
    var tmplist1 = listRuntimes.val().re开发者_如何学Goplace(initialvalue, tbedit.val());
    listIntermediate.html(tmplist1);
    tbedit.val("");
});

This is my suggestion, but It won't work :S

btnEdit = Edit button, listRuntimes = list with strings, initalvalue = the original value, tbedit = a textbox with the new value, listIntermediate = listbox that displays the values.


try:

$.each(listRuntimes, function(key, value) { 
  value.replace(initialvalue, tbedit.val());
});

Update:

var tmplist1 = [];
$.each(listRuntimes, function(key, value) { 
  tmplist1.push(value.replace(initialvalue, tbedit.val()));
});

or

$.each(listRuntimes, function(key, value) { 
  listRuntimes[key] = value.replace(initialvalue, tbedit.val());
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜