我有一個 html 表,其中包含我的 mysql db 表中的值??蛻粢髮ξ业?html 表中的數(shù)據(jù)進(jìn)行前端編輯。所以我在點擊時將 td 轉(zhuǎn)換為選擇框,用戶將在其中選擇 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); });我需要的是根據(jù)用戶從選擇框中選擇的內(nèi)容更新 td 的值。這是我嘗試過的:為選擇框進(jìn)行更改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"];它更新數(shù)據(jù)庫,但它在我進(jìn)行更改的 td 值中給出了 null 值。我認(rèn)為它在我的更新查詢中沒有得到 ':Remarks' 的值。有什么幫助嗎?
選擇框 onchange 時更新 mysql 表中的值
函數(shù)式編程
2021-06-28 12:56:30