jquery - JQuery 自动完成不会在模态窗口中触发
问题描述
我正在使用完美运行的 JQuery 自动完成功能。我有一个可以作为独立表单完美运行的表单(这意味着我可以通过 URL 访问它)但是当我将表单包含在 Bootstrap 模态框中时,JQuery 自动完成不会触发。
我正在渲染模态表单如下
function cloneProposal(id) {
$.ajax({
type: 'GET',
url: '@Url.Action("Clone", "Proposal")',
data:
{
id: id
},
cache: false,
success: function (result) {
document.getElementById("modalbody").innerHTML = result;
var modalBox = $('#myModal');
modalBox.attr("proposalnumber", id);
$("#modalTitle").html('Clone Proposal');
modalBox.modal('show');
},
error: function (response) {
alert('Bad Request ' + response.responseText);
}
});
}
表单正确呈现,但没有任何 JQuery 代码触发。有哪些可能的原因会导致这种情况发生?我什至编写了一个更改事件。当表单直接从 URL 执行时,它会正确触发,但在通过 Modal 呈现时不会。
$("input").change(function(){
alert("The text has been changed.");
});
控制台中没有错误。我不知所措。有人可以指出我正确的方向以弄清楚发生了什么吗?
谢谢一堆。
--- 值
解决方案
我终于通过改变加载模式的方式解决了这个问题。我将代码更改为以下内容,现在 JQuery 可以正确触发。
showInPopup = (url, title) => {
$.ajax({
type: "GET",
url: url,
success: function (res) {
$('#form-modal').modal('handleUpdate')
$('#form-modal .modal-body').html(res);
$('#form-modal .modal-title').html(title);
$('#form-modal').modal('show');
}
})
}
推荐阅读
- ios - 在带 Xcode 的设备上运行与在不带 Xcode 的设备上运行的行为差异
- ios - iOS 蓝牙无法通过自定义键盘扩展工作
- javascript - 如何检测浏览器后退按钮被禁用
- java - 接口的“通配符”导入
- php - 您必须在 php 代码中将 setcookie 放在哪里?
- php - 我如何在不使用 php 库的情况下制作 pdf?
- python - Django InlineModelAdmin 未正确显示内联表单集
- javascript - 检查对象的某个属性是否存在,只更新另一个属性
- python - 如何仅使用正则表达式将单词与数字匹配?
- r - 不能在 Blogdown 的 Rmd 文件中使用 Markdown 短代码