简体   繁体   English

如何使用具有相同名称的“数据目标”属性创建多个弹出窗口

[英]How to create multiple popup using with same name of “data-target” attribute

I am using bootstrap to create multiple popup models using data-target attribute. 我正在使用引导程序使用data-target属性创建多个弹出模型。

Like: 喜欢:

<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>

Now Working fine but i don't want use multiple data-target attribute and multiple popup model div. 现在工作正常,但我不想使用多个数据目标属性和多个弹出模型div。

I try to use only one data-target attribute name of all popup needed , and i want to replace my popup content with ajax response. 我尝试仅使用所有所需弹出窗口的一个数据目标属性名称,并且我想用ajax响应替换我的弹出窗口内容。

Now i am try to replace my response to existing popup , but did failed. 现在,我尝试替换对现有弹出窗口的响应,但没有成功。

$(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(){ 
        }); 
}

You have to trigger the DOM click event after this line: 您必须在此行之后触发DOM click事件:

$('#Favorites_Modal').html(response); 
$('#createNewFolder')[0].click(); // <-----this would trigger it.

I am not sure if .delegate() method is working. 我不确定.delegate()方法是否正常工作。 Instead the preferred way to event delegation is done by .on() method: 相反,事件委托的首选方法是通过.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(){ 
    });


}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM