森欄
2023-01-06 16:01:13
我是新手。我正在轉換一個包含發布表單的工作 Bootstrap 模式。使用帶有 Id 的按鈕打開模式。它總是在打開時顯示在 SQL while 語句結果列表中找到的第一條記錄的 FORM 內容。我將模態從 id 更改為一個類。我現在用類按鈕而不是 id 按鈕打開它。但是現在它一直顯示第二條記錄的表單內容。如果我從模態中取出表格,它可以正常工作并顯示正確的內容。accept-btn 打開模式。('.confirm-body') 包含模態內容表單。請感謝一些幫助。<!-- Opens modal is outside the modal--><a class="accept-btn">Accept</a><!-- The Modal --><div class="modal"> <!-- Modal content --> <div class="modal-content animate confirmarea-size"> <div id="topblue-border1" class="topblue-border1"></div> <!-- topblue border End --> <!-- Popup buttons Start --> <div class="confirm-body boxshadow" style="display:none;"> <form class="whatever" action="" method=""> <input type="hidden" class="whatever" name="" value="<?php echo whatever?>"> <input type="hidden" class="whatever" name="" value="<?php echo whatever?>"> <input type="hidden" class="whatever" name="" value="<?php echo whatever?>"> <div class="ajax-response"></div> <a><div id="css-btn" class="confirm-btn">Accept</div></a> <a><div id="css-btn" class="cancel-btn">Cancel</div></a> <a><div id="css-btn" class="nextstage-btn">OK</div></a> </form> </div> <!-- Popup Confirm Section END --> </div> <!-- End of The Modal Content --> </div> <!-- End of The Modal -->1st Option Button script<script>// Accept button Opens the Modal .$(document).ready(function() { $('.accept-btn').click(function(event) { $('.modal').show(); $('.confirm-body').show(); });});</script>2nd Option button script. I want to try something like this but I dont know how to code it and close it correctly. each recored has a record Id field. I want to relate the modal to the record id.
1 回答

拉風的咖菲貓
TA貢獻1995條經驗 獲得超2個贊
我已經解決了這個問題。一些繞過它的方法很好,比如 AJAX GET Posted here 是有效的。但我知道必須有另一種方法不需要 AJAX GET 命令,而是對模態進行微小的更改,因為我的另一個問題是我在另一個項目上的其他模態包含模態形式的用戶輸入字段,返回 Js 查詢在通過 Ajax 發布表單之前打開 mondal。經過大量的測試和痛苦之后,我找到了解決方案,因為我知道答案在于模態 ID 是靜態的。我怎樣才能使它動態并匹配 SQL $row id 和 Button ID。答案就在下面。
在包含行的 Sql 數據庫
$row [recordid]
或 ID 的 php 變量中創建。現在,這是確保您獲得正確數據所需的變量。
$id = "". $row["id"]."";
在您用來打開模式的按鈕中回顯記錄 id 變量。保持!變量前的哈希#:
<button type="button" class="accept-btn" data-toggle="modal" data-target="#<?php echo $id;?>">
模態 Div - 刪除#myModal 并回顯 id php 變量。不要放哈希#
<div id="<?php echo $id;?>" class="modal">
就這樣了。因此,當您單擊任何行中的模態按鈕時,它將顯示正確的內容/形式。
添加回答
舉報
0/150
提交
取消