javascript - 引导模式中未显示输入的数字

标签 javascript html bootstrap-modal

我试图将用户输入的数字显示到 Bootstrap 模式中,但由于某种原因它没有显示。模态出现但值“APno”没有出现在“预约号码”旁边,任何人都可以看到任何原因吗?

我的代码如下:

表单

<form method="POST">
     Appointment Number:<br>

  <input type="number" name="apno" id="apno">
  <br>
  <br><br>
  <input type="button" class="btn btn-success success" value="Submit" id="Submitbtn" name ="Submitbtn" data-toggle="modal" data-target="#confirm-submit">
</form> 

模态

<!-- Modal -->
<div class="modal" id="confirm-submit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                Add apppointment details
            </div>
            <div class="modal-body">
                Please add the following details

                <!-- Submit details -->
                <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="POST">
                    <tr>
                        <th>Appointment Number: </th>
                        <td id="APNo"></td>
                    </tr>
                    <br>
                    <label for "comments"> Comments: </label>
                    <br>
                    <textarea name="comments" rows="5" cols="30"></textarea>
                    <br>
                    <label for "prescriptions"> Prescriptions: </label>
                    <br>
                    <textarea name="prescriptions" rows="5" cols="30"></textarea>

                    <br><br>

                </form> 

            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-primary" data-dismiss="modal">Cancel</button>
                <a href="#" id="submit" class="btn btn-success success">Submit</a>
            </div>
        </div>
    </div>
</div>

JS

  $(document).ready(function() {



    $('#Submitbtn').click(function () {
        /* when the button in the form is clicked, display the entered values in the modal */

      $('#APNo').text($('#apno').val());


    });

    $('#submit').click(function () {
        // when the submit button in modal is clicked, submit the form 


         });
         });

最佳答案

您将数据放在 td 元素中,但您的 td 不包含在表格标签中。将您的表格元素包裹在表格标签中,它应该可以正常工作:

$(document).ready(function() {

  $('#Submitbtn').click(function() {
    /* when the button in the form is clicked, display the entered values in the modal */
    $('#APNo').text($('#apno').val());
  });

  $('#submit').click(function() {
    // when the submit button in modal is clicked, submit the form 


  });
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> Appointment Number:<br>

<input type="number" name="apno" id="apno">
<br>
<br><br>
<input type="button" class="btn btn-success success" value="Submit" id="Submitbtn" name="Submitbtn" data-toggle="modal" data-target="#confirm-submit">

<!-- Modal -->
<div class="modal" id="confirm-submit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        Add apppointment details
      </div>
      <div class="modal-body">
        Please add the following details

        <!-- Submit details -->
        <form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="POST">
          <table>
            <tr>
              <th>Appointment Number: </th>
              <td id="APNo"></td>
            </tr>
          </table>
          <br>
          <label for "comments"> Comments: </label>
          <br>
          <textarea name="comments" rows="5" cols="30"></textarea>
          <br>
          <label for "prescriptions"> Prescriptions: </label>
          <br>
          <textarea name="prescriptions" rows="5" cols="30"></textarea>

          <br><br>

        </form>

      </div>

      <div class="modal-footer">
        <button type="button" class="btn btn-primary" data-dismiss="modal">Cancel</button>
        <a href="#" id="submit" class="btn btn-success success">Submit</a>
      </div>
    </div>
  </div>
</div>

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

关于javascript - 引导模式中未显示输入的数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55483865/

相关文章:

javascript - 无法在本地 react 应用程序中下载pdf

html - 我如何使 2 行文本与 li 中的图像对齐

html - 设置 iframe 以占用页面中的剩余空间

html - 在 JSP 中搜索数据库

html - 使用 Materialise 卡与模态视图冲突

javascript - 尝试在 JavaScript 中迭代 JSON 数组时出错

javascript - 渲染事件后是否有 YUI 数据表?

javascript - 在 Bootstrap 模式框中加载外部页面

javascript - 将变量传递给 Bootstrap 模式

javascript - MERN Stack中如何进行子域路由?