Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript <;textarea>;设置新值时自动重置到顶部_Javascript_Jquery_Textarea - Fatal编程技术网

Javascript <;textarea>;设置新值时自动重置到顶部

Javascript <;textarea>;设置新值时自动重置到顶部,javascript,jquery,textarea,Javascript,Jquery,Textarea,HTML: <textarea rows="3" cols="50"> Cake cupcake sesame snaps. Cookie marshmallow bonbon faworki pie caramels. Icing tootsie roll jelly-o pudding bear claw. Candy topping fruitcake jelly... {Type something after this..} </textarea> $('

HTML:

<textarea rows="3" cols="50">
Cake cupcake sesame snaps. Cookie marshmallow bonbon faworki pie caramels. 
Icing tootsie roll jelly-o pudding bear claw. Candy topping fruitcake jelly...
{Type something after this..}
</textarea> 
$('textarea').on("keyup", function(e) {
      var val = $('<div/>').html($(this).val());
      $(this).val(val.text().replace(/'/g,"’"));
});

蛋糕蛋糕芝麻扣。饼干棉花糖邦邦法沃基派焦糖。
糖衣卷果冻布丁熊爪。糖果加水果蛋糕果冻。。。
{在此之后键入内容..}
jQuery:

<textarea rows="3" cols="50">
Cake cupcake sesame snaps. Cookie marshmallow bonbon faworki pie caramels. 
Icing tootsie roll jelly-o pudding bear claw. Candy topping fruitcake jelly...
{Type something after this..}
</textarea> 
$('textarea').on("keyup", function(e) {
      var val = $('<div/>').html($(this).val());
      $(this).val(val.text().replace(/'/g,"’"));
});
$('textarea')。打开(“键控”,函数(e){
var val=$('').html($(this.val());
$(this.val(val.text().replace(/“/g,”));
});
演示:

我有一个固定大小的
,当我在内容已满后键入时,我使用jQuery替换一些字符串以便

重置为顶部

有什么想法吗


更新:

<textarea rows="3" cols="50">
Cake cupcake sesame snaps. Cookie marshmallow bonbon faworki pie caramels. 
Icing tootsie roll jelly-o pudding bear claw. Candy topping fruitcake jelly...
{Type something after this..}
</textarea> 
$('textarea').on("keyup", function(e) {
      var val = $('<div/>').html($(this).val());
      $(this).val(val.text().replace(/'/g,"’"));
});
我确实喜欢这个

$('textarea').on("keyup", function(e) {
    var oldVal = $(this).val();
    var newVal = $('<div/>').html($(this).val());
    var newVal = newVal.text().replace(/'/g,"’");
    if(oldVal!=newVal) {
      $(this).val(newVal);
    }
});
$('textarea')。打开(“键控”,函数(e){
var oldVal=$(this.val();
var newVal=$('').html($(this.val());
var newVal=newVal.text();
if(oldVal!=newVal){
$(this.val)(newVal);
}
});

只要在值被替换时放入一个新的替换值,我想你需要在添加字符串时滚动到底部。这是我的密码

$('textarea').on("keyup", function(e) {
      var val = $('<div/>').html($(this).val());
      $(this).val(val.text().replace(/'/g,"’"));   
$(this).animate({
    scrollTop:$(document).height()
},1000)
});
$('textarea')。打开(“键控”,函数(e){
var val=$('').html($(this.val());
$(this.val(val.text().replace(/“/g,”));
$(此)。设置动画({
scrollTop:$(文档).height()
},1000)
});
此处文本区域设置为滚动