使用jQuery更新有关textarea值更改的文本 [英] Update text on textarea value change w/ jQuery
本文介绍了使用jQuery更新有关textarea值更改的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文本区域.通过键入或通过通过另一个jQuery函数在其中放置一些值或粘贴来更改textarea中的值时,我需要更新div中的文本.
I have a textarea. I need to update text in a div when a value in textarea is changed by either typing in it or by placing some value in it via another jQuery function or pasted.
$(document).ready(function(){
function myFunc() {
var input = $("#myTxt").val();
$("#txtHere").text(input);
}
myFunc();
// EDIT BELOW -- this will update while typing
$("#myTxt").keyup(myFunc);
});
<textarea id="myTxt"></textarea>
<div id="txtHere"></div>
它会在页面加载时加载值,但我不确定该使用什么来检查textarea中的值...
It loads the value on page load but I'm not sure what to use to check for value in the textarea...
推荐答案
$(document).ready(function(){
function myFunc(){
var input = $("#myTxt").val();
$("#txtHere").text(input);
}
myFunc();
//either this
$('#myTxt').keyup(function(){
$('#txtHere').html($(this).val());
});
//or this
$('#myTxt').keyup(function(){
myFunc();
});
//and this for good measure
$('#myTxt').change(function(){
myFunc(); //or direct assignment $('#txtHere').html($(this).val());
});
});
这篇关于使用jQuery更新有关textarea值更改的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文