<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 中的输入文本字段更改文本元素?

        时间:2023-06-19
        <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 中的输入文本字段更改文本元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:我无法在 html5 中的画布中获取图像,该怎么办? 下一篇:HTML5 Canvas 文本围绕圆圈制作动画

                  相关文章

                  <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>
                      <bdo id='8SKEL'></bdo><ul id='8SKEL'></ul>