文本字段更改时更改范围 [英] Change span when text field changes
本文介绍了文本字段更改时更改范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含多个文本字段的表单。当我在现场写东西时,我想更改一个span标签。像这样:
有什么想法?
解决方案
您可以使用 / code>,然后用
文本框
值替换 span
内容。
< input id =testtype =text/>
< span id =content>< / span>
$(#test)。keyup(function(){
$(#content)。html($(#test)。val());
});
编辑:
您也可以使用 $(this).val()
作为 pXL
建议。
$(#test)。keyup(function(){
var val = $(this)。 val();
$(#content)。html(val);
});
I have a form with several text fields. I want to change a span tag when I write something in the field. Like this:
Any ideas?
解决方案
You can use keyup
and then replace the span
content with the textbox
value.
<input id="test" type="text" />
<span id="content"></span>
$("#test").keyup(function() {
$("#content").html($("#test").val());
});
Edit:
You can also use $(this).val()
as pXL
has suggested.
$("#test").keyup(function() {
var val = $(this).val();
$("#content").html(val);
});
这篇关于文本字段更改时更改范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文