Javascript:使用Jquery在父输入内部输入时更新标签内容 [英] Javascript: Update label content while typing inside of a parent input with Jquery

查看:79
本文介绍了Javascript:使用Jquery在父输入内部输入时更新标签内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用jquery更新预览div的标签,当编辑div的父输入里面输入时?
谢谢。

How to update with jquery the label of preview div when im typing inside of the parent input of edit div? Thank you.

<html>
        <body>
                <div id="preview">
                        <label id="companyName" class="workExperience">
                                This is my company
                        </label>
                </div>
                <div id="edit">
                        <label>Company Name: </label>
                        <input type="text" id="companyName" />
                </div>
        </body>
</html>


推荐答案

您的代码:

You'd have to have something along these lines in your code:

<script>
$("#companyName").keyup(function () {
  var value = $(this).val();
  $(".workExperience").text(value);
}).keyup();
</script>

然而,我会不是给它们相同的id值,因为它可能会导致一些错误。

However, I would NOT give them the same id value, as it might lead to some errors.

祝你好运!

这篇关于Javascript:使用Jquery在父输入内部输入时更新标签内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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