我正在尝试将用户输入的数字显示在引导程序模式上,但是由于某些原因,它没有显示。出现模态,但“约会编号”旁边没有出现“ 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
});
});
答案 0 :(得分:1)
您正在将数据放置在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>