簡體   English   中英

帶有$(document).ready(function()的Javascript

[英]Javascript with $(document).ready(function()

我正在使用wenzhixin的bootstrap-table.js庫。 如果在加載頁面后運行$('p')。click(function()可以正常工作,則問題是如果我使用表過濾器,sort等的某些功能,那么我的功能將不起作用。

我試圖更改順序,jQuery.noConflict()但什么也沒有。

我附上了代碼。

非常感謝,

對不起,我的英語。

<!DOCTYPE html>
<html>
<head>
  <title>Imputacion</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="../clases/bootstrap-3.3.6-dist/css/bootstrap.min.css">
  <link rel="stylesheet" href="../clases/bootstrap-table-develop/src/bootstrap-table.css">
  <script src="../clases/jquery-1.12.3.min.js"></script>
  <script src="../clases/bootstrap-3.3.6-dist/js/bootstrap.min.js"></script>
  <script src="../clases/bootstrap-table-develop/src/bootstrap-table.js">      </script>
 <script>
 $(document).ready(function(){
   $('p').click(function() {
  alert("It is ok");
 });
 });
 </script>   
</head>
<body>
<div class="container">
                <table id="table"
           data-toggle="table"
           data-show-columns="true"
           data-show-toggle="true"
           data-show-pagination-switch="true"
           data-show-refresh="true"
           data-search="true"
           data-pagination="true"
           data-key-events="true"
           class="table-condensed" style="font-size:0.85em;" >
            <thead>
                <tr>
                <th data-field="codigo" data-sortable="true">codigo</th>
                <th data-field="id" data-sortable="true">Nombre</th>
                <th data-field="name" data-sortable="true" style="text-align:center">Inicio</th>
                <th data-field="price" data-sortable="true">Horario</th>
                <th data-field="a" data-sortable="true">Acción</th>
                </tr>        
            </thead>
            <tbody>
                <tr>
                    <td>EMAK1RF015</td>
                    <td>Eugenio </td>
                    <td style="text-align:center">16:40</td>
                    <td>8</td>
                    <td>    
                        <a href="#" class="abreModalFinal" data-id='123456789' data-toggle="tooltip" title="Final" ><p>Eugenio</p></a>      
                            </td>
                    </tr>   
                    </tbody>
                </table>
</div>
</body>
</html>

元素將在網頁的生命周期中稍后添加/更新,而不是在DOMContent准備就緒時添加/更新。

使用Event delegation

$(document).ready(function() {
  $('container').on('click', 'p', function() {
    alert("It is ok");
  });
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM