JQUERY在键入时将文本框的内容复制到字段 [英] JQUERY copy contents of a textbox to a field while typing

查看:77
本文介绍了JQUERY在键入时将文本框的内容复制到字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在用户键入时将文本框的内容同时复制到div中.这是 JSFIDDLE上的代码 面临的错误是,在div内复制的值的长度始终比文本框的长度短一.我在脚本中犯了什么错误?

I am trying to copy the contents of a textbox into a div simultaneously while the user is typing. Here is THE CODE ON JSFIDDLE The error that is am facing is, the length of the value copied inside the div is always one less than that of the textbox. what error am i making in the script?

推荐答案

请改用keyup.

$("#boxx").keyup(function(event) {
  var stt = $(this).val();
  $("div").text(stt);
});

keypress会在按下键时发生,并且您希望在释放键时传输文本.

keypress occurs when the key is pressed down and you want the text transferred when the key is released.

这篇关于JQUERY在键入时将文本框的内容复制到字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆