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());
});
精彩评论