当使用jquery动态创建链接时,函数不会将url传递给模态引导中的操作

时间:2015-04-23 21:14:40

标签: javascript jquery html ajax twitter-bootstrap

我使用jQuery

生成此引导链接(按钮)
<a class="deleteit btn btn-danger btn-sm" id="{{service['company']['slug']~'/'~service['customer']['_id']~'/'~service['service']['serviceId']}}" data-toggle="modal" data-target="#delete_dialog_all_services" title="Delete Service"><i class="glyphicon glyphicon-remove"></i></a>  

然后我用这个函数将url传递给modal中的form的action属性:

  $('.deleteit').click(function (event) {
   var myVal = $(this).attr('id');
    $('.formDel').attr('action', function(i, value) {
       return "{{url_for('services.delete_service',company_name='companyName', customer_id='customerID', service_id='serviceID')}}".replace('companyName/customerID/serviceID', myVal);
    });
  });

在这个模态中我有一个表单,我使用上面的函数

传递属性操作中的url
<!-- modal fail-safe -->
<div id="delete_dialog_all_services" class="modal">
    <div class="modal-dialog">
    <div class="modal-content">
    <div class="modal-header">
        <a href="#" data-dismiss="modal" aria-hidden="true" class="close">×</a>
        <h4>
           Confirm!
        </h4>
    </div>
    <div class="modal-body" align="center">
         <p><i class="glyphicon glyphicon-warning-sign"></i> This item will be permanently deleted and cannot be recovered. Are you sure?</p>
    </div>
    <div class="modal-footer">
        <div class="pull-right">
           <div class="col-xs-6">
              <form action="" class="formDel" method="get">
               <button type="submit" class="btn btn-danger">
               Yes
               </button>
           </form>
           </div>               
           <div class="col-xs-6">
              <a href="#" data-dismiss="modal" class="btn btn-default" aria-hidden="true">No</a>
           </div>
        </div>
    </div>
  </div>
</div>

我的问题是,当我动态生成,其示出了使用jQuery它不&#39的模态的链接;吨结合上点击的情况下,因而它不将URL传递到action属性中的模态形式。我认为jQuery范围或DOM构建有问题,或者我不知道是什么。 提前致谢!

0 个答案:

没有答案