簡體   English   中英

如何在模態內容內調用javascript函數?

[英]How to call javascript function inside modal content?

我有兩個帶有引導程序的php頁面。 在第一頁中,我正在調用用於插入每個員工數據的模式。 第二頁包含模式內容,它通過AJAX從第一頁調用。

這是我的代碼。

第1頁:

<table data-toggle="table"  data-show-refresh="true" data-show-toggle="true" data-show-columns="true" data-search="true" data-select-item-name="toolbar1" data-pagination="true" data-sort-name="name" data-sort-order="desc">
<thead>
 <tr>
    <th data-field="company" data-sortable="true" data-align="center">Company Name</th>
    <th data-field="owner" data-sortable="true" data-align="center">Owner Name</th>
    <th data-field="contact" data-sortable="true" data-align="center">Contact No</th>
    <th data-field="category" data-sortable="true" data-align="center">Category</th>
    <th data-field="payment" data-sortable="true" data-align="center">Payment</th>
    <th data-field="calendar" data-sortable="true" data-align="center">Calendar</th>
 </tr>
</thead>
<tbody>
    <?php
      $sql_user="SELECT * from empployee order by id desc ";
      $result_user=mysqli_query($con,$sql_user);
      while($user=mysqli_fetch_array($result_user,MYSQLI_ASSOC))
      {
    ?>
    <tr>
     <td><?php echo $user['company']; ?></td>
     <td><?php echo $user['firstname']." ".$user['lastname']; ?></td>
     <td><?php echo $user['mobile_number']; ?></td>
     <td><?php echo $user['desig']; ?></td>
     <td><?php echo $user['salary']; ?></td>
     <td><button type="button" class="btn btn-info btn-sm"  data-toggle="modal" data-target='<?php echo $id2;?>' value='<?php echo $user['company'];?>' onclick="add_lineup(this.value);"><i class="fa fa-pencil"></i>Add</button>
         <div class="modal fade" id="<?php echo $im2;?>" role="dialog" aria-hidden="true">
            <div class="modal-dialog modal-lg">
              <div class="modal-content" id='<?php echo $edit;?>'>
              </div>
            </div>
         </div></td></tr>     
</tbody>
</table>

第2頁:

<?php
    session_start();
    if(!isset($_SESSION['admin']))
    {
     header("location:../index.php");
    }
        include('../connection.php');
        $details_id = $_REQUEST['details_id'];
        $company_sql =  mysqli_query($con,"SELECT * FROM task where id='$details_id'");
        $data_company = mysqli_fetch_array($company_sql);
    ?>
    <form action="" method="post"  enctype="multipart/form-data">
    <div class="modal-header">
      <button type="button" class="close" data-dismiss="modal">&times;</button>
      <h4 class="modal-title">Task Details</h4>
    </div>
        <input type="hidden" name="id" value="<?php echo $details_id ?>">
        <div class="modal-body">
        <table data-toggle="table"  data-show-refresh="true" data-show-toggle="true" data-show-columns="true" data-search="true" data-select-item-name="toolbar2" data-pagination="true" data-sort-name="name2" data-sort-order="desc">
            <thead>
                <tr>
                    <th data-field="name" data-sortable="true" >Item Name</th>
                    <th data-field="days" data-sortable="true" >Days</th>
                    <th data-field="Select" data-sortable="true">Select</th>
                    <th data-field="date" data-sortable="true">Delivery Date</th>
      </tr>
            </thead>
            <tbody>
                <?php
                    $search_task_items = "select * from task";
                    $run_search_task_items = mysqli_query($con, $search_task_items);
                    if(!$run_search_task_items)
                    {
                        die(mysqli_error($con));
                    }
                    while($get_task_items = mysqli_fetch_array($run_search_task_items))
                    {
                ?>
                        <tr>
                        <td><?php echo $get_task_items['item_name']; ?></td>
                        <td><?php echo $get_task_items['req_days']; ?></td>
                        <td><input type="checkbox" id="select[]" value="<?php echo $get_task_items['id']; ?>" onclick="test()"></td>
                        <td><input type="text" id="delivery_date" value=""></td></tr>
                <?php
                    }
                ?>
            </tbody>
        </table>

        <div class="modal-footer">
            <button type="submit" class="btn btn-primary pull-right">Add Customer Line-up Items</button>
        </div>
    </form>

我的問題是,單擊復選框后,我想在第二頁上執行一些javascript函數。 請記住,第二頁內容將使用AJAX通過模式顯示。

希望我的問題清楚。 如果需要任何其他信息,我准備提供,但我想要這個答案。

謝謝。

如果我正確理解,則只需在復選框上添加onclick事件

onclick="if ($('input.checkbox_check').is(':checked')) {  //call your function here }"

或者在多個復選框的情況下,只需使用“ this”運算符

onclick="if ($(this).is(':checked')) {  //call your function here }"

暫無
暫無

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

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