javascript - jQuery replace all single character - Stack Overflow

I want to replace all characters in the textarea by a click using jQuery.For example:ə = e, ı = i, ...T

I want to replace all characters in the textarea by a click using jQuery.

For example:

ə = e, ı = i, ...

Thıs ıs əxamplə

By clicking it should be:

This is example

I want to replace all characters in the textarea by a click using jQuery.

For example:

ə = e, ı = i, ...

Thıs ıs əxamplə

By clicking it should be:

This is example

Share Improve this question asked Mar 22, 2011 at 17:31 seferovseferov 4,1613 gold badges41 silver badges76 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 3
$('textarea').html($('textarea').html().replace(/ə/g,'e'))

Adding on from Zikes

var replace_map={
    "ı":"i",
    "ə":"e"
};

$('textarea').click(function(){
    var ret='';
    $.each(this.value.split(''), function(i, str) {
        ret += replace_map[str] || str;
    })
    this.value = ret;
});

DEMO


UPDATED EDIT

var replace_map={
    "ı":"i",
    "ə":"e"
};

$('textarea').click(function(){
     this.value = $.map(this.value.split(''), function(str) {
        return replace_map[str] || str;
    }).join('');
});

UPDATED DEMO

HTML:

<textarea>Thıs ıs əxamplə</textarea>

JS:

var replace_map={
    "ı":"i",
    "ə":"e"
};

$('textarea').click(function(){
    this.value = this.value.replace(/./g,function(str){
        return replace_map[str] || str;
    })
});

I don't think you really need jQuery for that other than perhaps to select the textarea element (and then only for a microscopic amount of ease).

Past that you should be able to use just string.replace on the textarea content: https://developer.mozilla/en/JavaScript/Reference/Global_Objects/String/replace

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745193811a4615992.html

相关推荐

  • javascript - jQuery replace all single character - Stack Overflow

    I want to replace all characters in the textarea by a click using jQuery.For example:ə = e, ı = i, ...T

    2小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信