Я пытаюсь заменить текст в textarea с помощью jQuery regex. Но, похоже, это не работает. http://regexr.com/38t41 говорит, что мое регулярное выражение действительно. Но, похоже, это не работает. Вот JSFiddle http://jsfiddle.net/8uzn2/9/
HTML:
<button id="updt">Update</button>
<div id="header-code-area" class="codearea">
<textarea id="show_header" cols="88" rows="4">
<!-- Paste this code to the header of your website -->
<!--front--><link href='http://fonts.googleapis.com/css?family=Allerta Stencil' rel='stylesheet' type='text/css' />
</textarea>
</div>
JQuery:
$(document).ready(function() {
$("#updt").click(function () {
//replace in paragraph
var match1 = /<\!--front--><link\shref='http:\/\/fonts\.googleapis\.com\/css\?family=[\w+ \w+]+/
console.log(match1);
//update textarea
$("textarea#show_header").filter(function () {
var $this = $(this);
$this.html(function () {
return $this.html().replace(match1, "<!--front--><link href='http://fonts.googleapis.com/css?family=");
});
}); //end textarea
});
});
Для установки значения элементов формы вы должны использовать метод val
.
$("#show_header").val(function (i, currentVal) {
return currentVal.replace(match1, "<!--front--><link href='http://fonts.googleapis.com/css?family=");
});
filter
здесь?