这是一个使用 jQuery、阿贾克斯、菲律宾比索、MySQL 和 HTML 的注释系统。当我单击“编辑”按钮时,它显示MySQL表第一行的注释,而不是我选择的行。但是,一旦我编辑它,它确实会更正正确的行。我无法找到显示要编辑的行的注释的方法。
我可以在文本区域中显示行的正确comment_id,但它会在文本区域中显示第一行的注释。
下面是测试用例代码:
MySQL表有两行:comment_id作为主行和文本注释。我将数据库命名为:testcaseedit_db,并将表命名为:tbl_comment。
索引.php
<?php $connect = new PDO('mysql:host=localhost;dbname=testcaseedit_db', 'root', ''); ?>
<div id="display_comment"></div>
<div id="comment_message"></div>
<div id="display_edit"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
let count = 0;
$(document).on('click change', '.edit, .submit', function(e) {
if ($(this).is('.edit')) {
var comment_id = $(this).attr("id");
$('#comment_id').val(comment_id);
var closestDiv = $('button').closest('div.panel');
$('.div.panel').not(closestDiv.next('.div.panel')).hide();
closestDiv.next('div.panel').slideToggle(100);
var commentEdit = $('#display_comment').find('#editable').html();
++count;
const htmlString =
`<form id="comment_form${count}" class="input-group form-row" action="edit.php" method="post" enctype="multipart/form-data">
<div class="input-group-prepend">
<textarea name="comment" id="comment${count}" class="form-control" rows="30" cols="160">
${commentEdit} ${comment_id}
</textarea>
</div>
<div class="input-group-prepend">
<input type="hidden" name="comment_id" id="comment_id" value="${comment_id}" />
<input type="submit" name="submit" id="submit" class="submit btn btn-info" value="Save" form="comment_form${count}" />
</div>
</form>`;
$('#display_comment')[0].insertAdjacentHTML('afterend', htmlString);
}
www说
喵喵时光机
随时随地看视频慕课网APP