I'm trying to replace parts of a Val() in jquery with some text but am not sure how to do this. $(this).val()
returns "# number of...." - I would like to replace #
with custom text, but Val doesn't seem to have a replace()
function. I'm quite new to JQuery, so I might be missing something obvious.
Thanks for any help
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You can pass a function to .val()
in 1.4+ like this:
$("#mySelector").val(function(i, v) { //index, current value
return v.replace("#","Custom Text");
});
回答2:
Do not forget to add a .val() at the end :
$("#mySelector").val(function(i, v) {return v.replace("#","Custom Text");}).val();