亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何將變量傳遞給引導模式表單并運行 mysql 查詢

如何將變量傳遞給引導模式表單并運行 mysql 查詢

PHP
慕容3067478 2021-11-05 10:26:18
我有一個包含兩個表的頁面:客戶和車站。一個 sql 查詢用數據填充這些表。我在表格的每一行上定義了一個按鈕來打開一個模態編輯表單。對于客戶:<table id = "admin_table_customers"  class="table rtl table-sm table-dark table-hover">  <tr>    <th>customer_id</th>    <th>name</th>    <th>&nbsp;</th>    <th>&nbsp;</th>  </tr>  <?php foreach($query_customers as $customer) { ?>    <tr>      <td><?php echo h($customer['CUSTOMER_ID']) ?></td>      <td><?php echo h($customer['CUSTOMER_NAME']) ?></td>      <td><button type="button" id="button_edit_customer" class="btn btn-primary feed-id" data-toggle="modal" data-target="#edit_customer" data-id="<?php echo h(u($customer['CUSTOMER_ID'])) ?>">edit</button></td>      <td><button type="button" id="button_delete_customer" class="btn btn-primary feed-id" data-toggle="modal" data-target="#delete_customer" data-id="<?php echo h(u($customer['CUSTOMER_ID'])) ?>">delete</button></td>    </tr>  <?php } ?></table>當我在 chrome 中檢查源時,一切(id 和 data-id)看起來都很好。我使用這個腳本來檢查是否將正確的值傳遞給模態表單。$(document).ready(function () {  $("#button_edit_station").click(function(evt){    alert($(this).attr("id"));    alert($(this).data('id'));  });  $("#button_edit_customer").click(function(evt){    alert($(this).attr("id"));    alert($(this).data('id'));  });});第一個問題:每個表第一行的按鈕顯示正確的值,但其他按鈕不顯示對話框。我想將每個表的 ID 傳遞給模態表單并執行查詢來填充表單。我想我可以設法將 ID 傳遞給模態,但是我應該如何以及何時執行查詢來填寫表單?這是我的表格:<div id="edit_customer" class="modal fade" role="dialog" data-backdrop="static">  <div class="modal-dialog">    <div class="modal-content">      <div class="modal-header rtl">        <h4 class="modal-title">edit customer</h4>      </div>
查看完整描述

2 回答

?
慕沐林林

TA貢獻2016條經驗 獲得超9個贊

按照以下步驟

  1. 在按鈕單擊事件“edit_modal(id,name)”上調用函數

  2. 在你的頁面上寫一個函數

函數edit_modal(id,name){

// assign value in modal form

$('#form_edit_customer_id').val(id);

$('#form_edit_customer_name').val(name);


//Display modal

$('#edit_customer').modal('show');

}


查看完整回答
反對 回復 2021-11-05
?
忽然笑

TA貢獻1806條經驗 獲得超5個贊

我用了不同的方式來實現我的目標。這是我改編的鏈接: PHP Ajax Insert Data in MySQL By Using Bootstrap Modal


查看完整回答
反對 回復 2021-11-05
  • 2 回答
  • 0 關注
  • 169 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號