<i id='91Dq3'><tr id='91Dq3'><dt id='91Dq3'><q id='91Dq3'><span id='91Dq3'><b id='91Dq3'><form id='91Dq3'><ins id='91Dq3'></ins><ul id='91Dq3'></ul><sub id='91Dq3'></sub></form><legend id='91Dq3'></legend><bdo id='91Dq3'><pre id='91Dq3'><center id='91Dq3'></center></pre></bdo></b><th id='91Dq3'></th></span></q></dt></tr></i><div id='91Dq3'><tfoot id='91Dq3'></tfoot><dl id='91Dq3'><fieldset id='91Dq3'></fieldset></dl></div>

      <tfoot id='91Dq3'></tfoot>
        <bdo id='91Dq3'></bdo><ul id='91Dq3'></ul>

      <small id='91Dq3'></small><noframes id='91Dq3'>

      1. <legend id='91Dq3'><style id='91Dq3'><dir id='91Dq3'><q id='91Dq3'></q></dir></style></legend>

        如何使用 Javascript 根据 HTML 中的输入文本字段更改文本元素?

        How to change text element based on input text field in HTML using Javascript?(如何使用 Javascript 根据 HTML 中的输入文本字段更改文本元素?)
        <legend id='iXU7x'><style id='iXU7x'><dir id='iXU7x'><q id='iXU7x'></q></dir></style></legend>
        <tfoot id='iXU7x'></tfoot>
          <i id='iXU7x'><tr id='iXU7x'><dt id='iXU7x'><q id='iXU7x'><span id='iXU7x'><b id='iXU7x'><form id='iXU7x'><ins id='iXU7x'></ins><ul id='iXU7x'></ul><sub id='iXU7x'></sub></form><legend id='iXU7x'></legend><bdo id='iXU7x'><pre id='iXU7x'><center id='iXU7x'></center></pre></bdo></b><th id='iXU7x'></th></span></q></dt></tr></i><div id='iXU7x'><tfoot id='iXU7x'></tfoot><dl id='iXU7x'><fieldset id='iXU7x'></fieldset></dl></div>
            <bdo id='iXU7x'></bdo><ul id='iXU7x'></ul>
              <tbody id='iXU7x'></tbody>

                1. <small id='iXU7x'></small><noframes id='iXU7x'>

                2. 本文介绍了如何使用 Javascript 根据 HTML 中的输入文本字段更改文本元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  这是我的代码副本:https://jsfiddle.net/5zLyyv94/

                  <h1 class="login-heading">
                  <a href="./index.html" class="lnk2">Join</a> us, 
                  <span id="initname">Luke</span>.</h1>
                  <form method="post">
                  <input type="text" name="first name" placeholder="First Name" required="required" class="input-txt" />
                  </form>
                  

                  基本上,我正在尝试将名称从 Luke 更改为人在名字字段文本中键入的任何内容.

                  Basicially, i'm trying to change the name from Luke to whatever the person types into the field text for first name.

                  也就是说,他们输入的名字是Jason"

                  so say, they type in their first name as "Jason"

                  我希望 Luke 的 span 文本从 Luke 更改为 Jason.

                  I want the span text for Luke to change from Luke to Jason.

                  提前致谢!

                  推荐答案

                  这应该可以帮助您开始(必须在字段外单击才能进行更新):

                  This should get you started (must click outside the field for update to happen):

                  $('input[name=first_name]').blur(function(){
                    $('#initname').text( this.value );
                  });

                  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
                  
                  <h1 class="login-heading">
                  <a href="./index.html" class="lnk2">Join</a> us, 
                  <span id="initname">Luke</span>.</h1>
                  
                  <form method="post">
                    <input type="text" name="first_name" placeholder="First Name" required="required" class="input-txt" />
                  </form>

                  也可以使用keyup()方法实时改变span文本:

                  You can also use the keyup() method to change the span text in real time:

                  $('input[name=first_name]').keyup(function(){
                    $('#initname').text( this.value );
                  });

                  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
                  
                  <h1 class="login-heading">
                  <a href="./index.html" class="lnk2">Join</a> us, 
                  <span id="initname">Luke</span>.</h1>
                  
                  <form method="post">
                    <input type="text" name="first_name" placeholder="First Name" required="required" class="input-txt" />
                  </form>

                  或者,在用户停止输入 1.2 秒(1200 毫秒)后:

                  Or, after user stops typing for 1.2 seconds (1200 milliseconds):

                  pauseTime = 1200;
                  
                  $('input[name=first_name]').keyup(debounce(function(event){
                    $('#initname').text( this.value );
                  },pauseTime));
                  
                  function debounce(fn, delay) {
                    var timer = null;
                    return function () {
                      var context = this, args = arguments;
                      clearTimeout(timer);
                      timer = setTimeout(function () {
                        fn.apply(context, args);
                      }, delay);
                    };
                  }

                  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
                  
                  <h1 class="login-heading">
                  <a href="./index.html" class="lnk2">Join</a> us, 
                  <span id="initname">Luke</span>.</h1>
                  
                  <form method="post">
                    <input type="text" name="first_name" placeholder="First Name" required="required" class="input-txt" />
                  </form>

                  参考资料:

                  https://remysharp.com/2010/07/21/throttling-函数调用

                  这篇关于如何使用 Javascript 根据 HTML 中的输入文本字段更改文本元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How does object-fit work with canvas element?(对象适合如何与画布元素一起使用?)
                  How to make rooftext effect and valley text effect in HTML5 (or Fabric.js)(如何在 HTML5(或 Fabric.js)中制作屋顶文字效果和山谷文字效果)
                  Draw border around nontransparent part of image on canvas(在画布上的图像不透明部分周围绘制边框)
                  dragging and resizing an image on html5 canvas(在 html5 画布上拖动图像并调整其大小)
                  What#39;s the difference between a boolean as primitive and a boolean as property of an object?(作为原始对象的布尔值和作为对象属性的布尔值有什么区别?)
                  I want to do animation of an object along a particular path(我想沿特定路径对对象进行动画处理)
                  <legend id='8SKEL'><style id='8SKEL'><dir id='8SKEL'><q id='8SKEL'></q></dir></style></legend>

                  <small id='8SKEL'></small><noframes id='8SKEL'>

                3. <i id='8SKEL'><tr id='8SKEL'><dt id='8SKEL'><q id='8SKEL'><span id='8SKEL'><b id='8SKEL'><form id='8SKEL'><ins id='8SKEL'></ins><ul id='8SKEL'></ul><sub id='8SKEL'></sub></form><legend id='8SKEL'></legend><bdo id='8SKEL'><pre id='8SKEL'><center id='8SKEL'></center></pre></bdo></b><th id='8SKEL'></th></span></q></dt></tr></i><div id='8SKEL'><tfoot id='8SKEL'></tfoot><dl id='8SKEL'><fieldset id='8SKEL'></fieldset></dl></div>

                      <tfoot id='8SKEL'></tfoot>
                        <tbody id='8SKEL'></tbody>
                        <bdo id='8SKEL'></bdo><ul id='8SKEL'></ul>