我正在使用引导程序使用data-target属性创建多个弹出模型。
喜欢:
<a class="result-right-icon" id="createNewFolder" data-target="#Favorites_Modal" data-toggle="modal" href="" data-keyboard="false" data-backdrop="static">Favorites</a>
<a class="result-right-icon" data-target="#recentview_Modal" data-toggle="modal" href="" data-keyboard="false" data-backdrop="static">Recent View</a>
<div class="modal fade" id="Favorites_Modal" role="dialog">
<div class="modal-dialog modal-sm sr_popup">
<div class="modal-content sr_popup_content">
<div class="modal-header sr_pop_heading">
</div>
<div class="modal-body">
<a id="createNewFolder" data-target="">Open Popup </a>
</div>
</div>
</div>
</div>
<div class="modal fade" id="recentview_Modal" role="dialog">
<div class="modal-dialog modal-sm sr_popup">
<div class="modal-content sr_popup_content">
<div class="modal-header sr_pop_heading">
</div>
<div class="modal-body">
<a id="createNewFolder" data-target="">Open Popup </a>
</div>
</div>
</div>
</div>
现在工作正常,但我不想使用多个数据目标属性和多个弹出模型div。
我尝试仅使用所有需要的弹出窗口的一个数据目标属性名称,并且我想用ajax响应替换我的弹出窗口内容。
现在,我尝试替换对现有弹出窗口的响应,但失败了。
$(document).delegate('#createNewFolder', 'click', function(){
createNewSaveDocFoldView();
});
function createNewSaveDocFoldView(){
jQuery.post(createNewFoldURL).success(function(response){
//$('#Favorites_Modal').html("");
$('#Favorites_Modal').empty("");
$('#Favorites_Modal').html(response);
}).error(function(){
});
}
您必须在此行之后触发DOM click事件:
$('#Favorites_Modal').html(response);
$('#createNewFolder')[0].click(); // <-----this would trigger it.
我不确定该.delegate()
方法是否有效。相反,事件委托的首选方法是通过.on()
方法完成:
$(document).on('click', '#createNewFolder', createNewSaveDocFoldView);
function createNewSaveDocFoldView(){
jQuery.post(createNewFoldURL).success(function(response){
//$('#Favorites_Modal').html("");
$('#Favorites_Modal').empty("");
$('#Favorites_Modal').html(response);
$('#createNewFolder')[0].click(); // <-----this would trigger it.
}).error(function(){
});
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句