javascript - How to change textbox value on key up in jquery? - Stack Overflow

I just want to change the VALUE attribute of textbox on key up. But when I am typing something the valu

I just want to change the VALUE attribute of textbox on key up. But when I am typing something the value remains same in the mark up. I want to change it in mark up too. Here is my jsfiddle .

MARK UP

<input type="text" value="Type Your Name" id="textBox1" />
<span id="userName"></span>

jQuery

$("#textBox1").keyup(function () {

 $("#userName").text($(this).val());

});

Any help would be highly appreciated.

I just want to change the VALUE attribute of textbox on key up. But when I am typing something the value remains same in the mark up. I want to change it in mark up too. Here is my jsfiddle .

MARK UP

<input type="text" value="Type Your Name" id="textBox1" />
<span id="userName"></span>

jQuery

$("#textBox1").keyup(function () {

 $("#userName").text($(this).val());

});

Any help would be highly appreciated.

Share Improve this question asked Mar 16, 2014 at 22:42 Fazil MirFazil Mir 8332 gold badges10 silver badges26 bronze badges 1
  • your submited code working good for me! what is the problem!? – peiman F. Commented Mar 16, 2014 at 23:52
Add a ment  | 

3 Answers 3

Reset to default 4

add this line to your code:

    $("#textBox1").attr('value', $(this).val())

check your updated fiddle http://jsfiddle/h5tpk/6/

just wrap your code in

$(function(){

});

http://jsfiddle/h5tpk/5/

You could also access the textbox via:

$("#textBox1").keyup(function () {
  $("#userName").text($('#textBox1').val());
});

http://jsfiddle/#&togetherjs=kTauiAAFgR

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

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信