javascript 输入更改时jquery文本更改
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4982955/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 15:33:53 来源:igfitidea点击:
jquery text change when input change
提问by Adam Ramadhan
How can we do like the bottom, the simple way ?
我们怎么能像底部一样,简单的方法?
?
?
it updates when we change the input.
当我们更改输入时它会更新。
回答by Jacob Relkin
Say you had the following HTML:
假设您有以下 HTML:
<input type="text" id="textbox"/>
<span>http://twitter.com/<span id="changeable_text"></span></span>
Your JS would listen for the keyupevent.
您的 JS 会监听该keyup事件。
$('input#textbox').keyup(function() {
//perform ajax call...
$('#changeable_text').text($(this).val());
});
回答by Marko
Just attach to the keyupevent of that textbox and update a span accordingly.
只需附加到该keyup文本框的事件并相应地更新跨度。
The textbox and span
文本框和跨度
<input type="text" id="txt-url-suffix" />
<div>Your public profile: http://www.twitter.com/<span id="url-suffix" /></div>
And some simple jQuery
还有一些简单的 jQuery
var $urlSuffix = $("#url-suffix");
$("#txt-url-suffix").keyup(function() {
var value = $(this).val();
$urlSuffix.text(value);
});

