开发者

replace textarea in jquery

开发者 https://www.devze.com 2022-12-11 18:46 出处:网络
I\'m trying to Replace a %%%VERSION%%% text, the text is coming from an tinyMCE editor. looks like this.

I'm trying to Replace a %%%VERSION%%% text, the text is coming from an tinyMCE editor.

looks like this.

$("#description textarea").val($("#description textarea").val().replace(/%%%VERSION%%%/开发者_开发知识库g, STAT_VERSION_INFO));

The value of the textearea is:

<textarea rows="20" cols="117" name="description" id="description">Some code version info: %%%VERSION%%%</textarea>

But i can't make it replace anything.


Use html() for textareas...

var txt = $("#description");
txt.html(txt.html().replace(/%%%VERSION%%%/g, '');


Change .val() to .html() and it works: Example here http://jsbin.com/uwidu/


To select: $("#description textarea") => $("textarea#description") or just $("#description")

To do the changes:

var textarea = $("textarea#description");
var text = textarea.html().replace(/%%%VERSION%%%/g, '');
textarea.html(text);


Just replace $("#description textarea") with $("#description") or $("textarea#description"). The first selector will look for a textarea inside a DOM element with id=description, while in your case it is the textarea that has id=description.

Hope this makes sense.

0

精彩评论

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