javascript - 在模态的 AJAX 中动态生成引导模态我正在尝试使用 AutoNumeric 4.6 但这不起作用(PHP)
问题描述
我在我的项目中使用https://makitweb.com/dynamically-load-content-in-bootstrap-modal-with-ajax/ 。
我正在尝试在 Ajax 的输入类型文本中使用 Autonumeric 4.6 生成引导模式。
我在一般的 html 文件、php 文件中添加了 AutoNumeric 脚本,什么都没有。脚本工作但不是 AJAX 生成模式。
请帮忙
我的代码:
HTML
<!-- Modal -->
<div class="modal fade" id="empModal" role="dialog" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog modal-xl">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Current Money</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
AJAX
$(document).ready(function(){
$('.CurrentMoney').click(function(){
var CurrentMoney= $(this).data('id');
$.ajax({
url: '../Server-Side/CurrentMoney.php',
type: 'post',
data: {CurrentMoney: CurrentMoney},
success: function(response){
// Add response in Modal body
$('.modal-body').html(response);
// Display Modal
$('#empModal').modal('show');
}
});
});
});
CurrentMoney.php
<?php
if(isset($_POST['CurrentMoney']))
{
$response = '<input type="text" class="AutoNumeric">';
echo $response;
}
else {
$response = 'Error';
echo $response;
}
exit;
?>
自动数值库
<!-- autonumeric4 -->
<script src="../plugins/autoNumeric/src/autonumeric4.6.js"></script>
<script>
const autoNumericOptionsEuro = {
digitGroupSeparator : ' ',
allowDecimalPadding: false
};
new AutoNumeric('.AutoNumeric', autoNumericOptionsEuro);
</script>
JSFiddle - 代码 https://jsfiddle.net/Fox21/ht1kyuvw/3/
解决方案
ajax 调用完成后调用 AutoNumeric 库
类似的东西
$(文档).ready(函数(){
$('.CurrentMoney').click(function(){
var CurrentMoney= $(this).data('id');
$.ajax({
url: '../Server-Side/CurrentMoney.php',
type: 'post',
data: {CurrentMoney: CurrentMoney},
success: function(response){
// Add response in Modal body
$('.modal-body').html(response);
// Display Modal
$('#empModal').modal('show');
const autoNumericOptionsEuro = {
digitGroupSeparator : ' ',
allowDecimalPadding: false
};
new AutoNumeric('.AutoNumeric', autoNumericOptionsEuro);
}
});
});
});
推荐阅读
- sql - 如何根据条件按结果集从组中获取数据?
- python - 将 Python 2.7x 转换为 3.x 兼容性问题:格式和 subprocess.Popen、numpy.array 和浮点数的问题
- oracle - 一列中的多个值显示另一列中的单个值
- java - HttpURLConnection 发送带有自定义标头的 POST 的 401 响应代码
- javascript - 使用map和dataservice同步获取数据
- c# - 如何存储表达式
其中 T :将自定义类转换为表达式 财产? - python - 计算从 for 循环返回的所有值的总值
- eclipse - 为什么 Tycho 将某些 Eclipse 插件包含在物化产品中?
- c# - 当应用程序作为服务运行时,IDataProtector 无法解密
- swift - 如何覆盖 Swift 包管理器的“unsafeFlags”行为?