使用JavaScript显示随机数列表,并将其显示在Modal上



我有JavaScript编码,可以生成随机数,现在我想在每次单击提交按钮时在模态上显示随机数。在哪里显示我要把随机数变量显示在模态上?

<script>
$(document).ready(function(){$("#mybtn").click(function(){
$("#myModal").modal();
$('#company').html($('#company').val());

function randomNumber(min, max) {  
min = Math.ceil(min); 
max = Math.floor(max); 
return Math.floor(Math.random() * (max - min + 1)) + min; 
}  
//// I want to show it on the modal it will display the company name and random number
document.write( randomNumber(9551008730006, 9551008730100) );
});
$("#myModal").modal("hide").on("hidden.bs.modal", function () {        
location.reload();                   
}); 
</script>
<form id="inputform" type="text" method="post">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="company">Company Name</label>
<input type="text" class="form-control" placeholder="ABC Bakers" id="company" readonly>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="prefix">Company Prefix</label>
<input type="text" class="form-control" placeholder="1234" id="prefix" readonly>
</div>
</div>
</div>
<label for="InputFile">Product Image input</label>
<input type="file" id="InputFile" required>
</div><button input type="button" name="btn" value="Submit" id="mybtn" data-toggle="modal" data-target="#confirm-submit">Submit</button> 
<div class="modal fade" id="confirm-submit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Hello</h4><button type="button" class="close" data-dismiss="modal">×</button></div><div class="modal-body"> 
<h4 id="company">  </h4>Thank You for your submission! Your <br id="randomnum">. Please check your product information.</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>

只需使用以下js来显示联系人和随机数上的随机数

<script>
$(document).ready(function(){
function randomNumber(min, max) {  
min = Math.ceil(min); 
max = Math.floor(max); 
return Math.floor(Math.random() * (max - min + 1)) + min; 
}
$("#mybtn").click(function(){
$("#myModal").modal();
var randomNo = randomNumber(9551008730006, 9551008730100)
$('#company').html(randomNo);                       
$('#randomnum').html(randomNo);
});
$("#myModal").modal("hide").on("hidden.bs.modal", function () {        
location.reload();                   
}); 
</script>

最新更新