简体   繁体   English

单击动态创建的DOM

[英]Click on Dynamically created DOM

I have this HTML Bootstrap 3 code for modal window: 我有以下HTML Bootstrap 3代码用于模式窗口:

<!-- Modal DELETE-->
<div class="modal fade" id="delete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="myModalLabel">Brisanje</h4>
      </div>
      <div class="modal-body">
        Da li ste sigurni da zelite da obrisete ovu parcelu iz baze?
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" id="brisi" class="btn btn-danger">Save changes</button>
      </div>
    </div>
  </div>
</div>

I try to open this modal with code that is dinamicly created: 我尝试使用动态创建的代码打开此模式:

"targets": 8,
                        "data": "akcija",
                        "render": function(data, type, full, meta) {
                            // return data; 
                            return '<div style="float:right;"><button class="btn btn-warning">Izmeni</button> <button data-toggle="modal" data-target="#delete" class="btn btn-info">Izvestaj o parceli</button> <i data-toggle="modal" data-target="#delete" class="fa fa-times"></i></div>';
                        }

so as you can see I add this: <i data-toggle="modal" data-target="#delete" class="fa fa-times"></i> to DOM , but when I click I canT open modal... 如您所见,我在DOM上添加了<i data-toggle="modal" data-target="#delete" class="fa fa-times"></i> ,但是当我单击时,我无法打开modal ...

What is the probem here? 这里有什么问题?

It looks like you are trying to write the html to the DOM, but your question is unclear. 看来您正在尝试将html写入DOM,但您的问题尚不清楚。

Using JQuery you would write the contents on the div to another container taht is already in the DOM like so: 使用JQuery,您可以将div上的内容写入另一个已经在DOM中的容器ht中,如下所示:

<div id="container"></div>

You can the write the contents to the container with jquery: 您可以使用jquery将内容写入容器:

$("#container").html('<div style="float:right;"><button class="btn btn-warning">Izmeni</button> <button data-toggle="modal" data-target="#delete" class="btn btn-info">Izvestaj o parceli</button> <i data-toggle="modal" data-target="#delete" class="fa fa-times"></i></div>');

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

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