我有一個 html 表,其中包含我的 mysql db 表中的值。客戶要求對我的 html 表中的數據進行前端編輯。所以我在點擊時將 td 轉換為選擇框,用戶將在其中選擇 X 和 O 備注。這是我的腳本: $(document).on('click', 'td', function() { ////---make td transform to dropdown list box when click---/// if($(this).find('select').length == 0) { $(this).empty(); //clears out current text in the table $(this).append('<select onchange="myFunction()" id="Remarks" name="Remarks"><option value=""></option><option <?php if ($Remarks=='X') echo 'selected';?> value="X" style="font-size:20px;font-weight:bold;">X<option style="font-size:20px;color:green;font-weight:bold;" <?php if ($Remarks=='O') echo 'selected';?> value="O">O</select>'); } }); $(document).on('focusout', 'td select', function(){ var myValue = $(this).val(); var $parent = $(this).parent(); $(this).remove(); $parent.append(myValue); });我需要的是根據用戶從選擇框中選擇的內容更新 td 的值。這是我嘗試過的:為選擇框進行更改function myFunction(){ var emp_name = document.getElementById('employeeName').value; var r = document.getElementById('Remarks').value; $.ajax({ type: 'post', url: 'update_data.php', data: { 'employeeName' :emp_name, 'DAY1' : r }, success: function(data){ $("#content").html(data) $(".loader").fadeOut("veryslow"); $("#content").hide().fadeIn(500) //alert(r); //alert(emp_name); }, error:function(data){ alert('Failed'); } }) };這是我的 update_data.php :<?php $employeeName = $_REQUEST["employeeName"]; $Remarks = $_REQUEST["Remarks"]; //$id = $_REQUEST["id"];它更新數據庫,但它在我進行更改的 td 值中給出了 null 值。我認為它在我的更新查詢中沒有得到 ':Remarks' 的值。有什么幫助嗎?
選擇框 onchange 時更新 mysql 表中的值
函數式編程
2021-06-28 12:56:30