我试图每次用户单击测试按钮时用标签显示输入的输入值,每次用户在输入部分输入新值时都应更新输入值,这意味着应删除以前的值。

在这里,我已经尝试过,但是以某种方式我无法显示输入的值。




      $(document).ready(function () {

          var testBtnSrc = document.getElementById("test_btn_src");
            testBtnSrc.addEventListener("click", function(){
              $('inp_src_success').append($('inp_src').val());
            });
                });

<title></title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
      </head>
      <body>
        <div id = "inp_src_success">
          <label>input value here </label>
        </div>
        <div>
          <label>Enter</label>
          <input  id = "inp_src" name="txtbox_ip_src" minlength="7" maxlength="15" class="form-control" type="text"
              placeholder="Source Server Ip:"
              pattern="(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"
              required onkeypress="myFunction()" />
              <div id = "inp_src1"></div>
              <button id  = "test_btn_src" class="btn btn-primary success" type="button" style=" font-size: 10px; margin-top:7px;">Test</button>
        </div>

最佳答案

尝试遵循jQuery代码

$(document).ready(function () {
  $('#test_btn_src').click(function(){
    $('#inp_src_success').text($('#inp_src').val());
  });
});

10-05 20:42
查看更多