在情态动词中不能识别id

IDs not being recognized when placed in modals

本文关键字:不能 识别 id      更新时间:2023-09-26

我正在创建一个注册表单,其内容包含在div(隐藏)中,然后当用户单击按钮时,模式显示并通过div的ID加载内容。

但是,我遇到了一个问题,在我的脚本中无法识别DIV的按钮。我使用jquery分配了一个点击事件,但它不起作用。可能是因为隐藏的DIV与在模态中创建的DIV有冲突(它们最终将具有相同的id)。

下面是我的脚本:
$('#addCollege').click(function(e){
    modal.open({content: $('#addCollegeForm').html()});
    e.preventDefault();`
});

这是DIV

<div id="addCollegeForm" style="display:none">
    <label>College:</label><br>
    <input type="text" placeholder = "Enter college name here..." id = "collegeDescription" > <br>
    <input type="button" value="Save" id= "addCollege">
</div>

谢谢你的帮助。

我为bootstrap编写了一个对话框插件,并得到了类似的问题。
我想弹出一个现有的dom元素。

解决方案:

$targetElement.detach().appendTo($window.find('.modal-body')) // $targetElement is an existing dom

分离元素并将其附加到容器中。

别忘了把元素恢复到原来的容器。
希望能有所帮助。

尝试将打开对话框的按钮移出对话框:

EDIT -像这样的东西应该可以工作…

HTML…

<div id="addCollegeForm">things in your dialog</div>
<input type="button" value="open dialog" id="addCollege">
jquery…

$("#addCollegeForm").dialog({
    autoOpen: false
});

$('#addCollege').click(function () {
    $("#addCollegeForm").dialog("open");
});
http://jsfiddle.net/DTq6m/

http://api.jqueryui.com/dialog/option-autoOpen