国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

在PHP MySQL中,將預(yù)設(shè)的POST值加入到動(dòng)態(tài)建立的輸入行欄位中。
P粉409742142
P粉409742142 2023-07-30 10:10:35
0
1
562
<p>我正在開發(fā)一個(gè)與表格整合的小型HTML表單。表格中有一個(gè)名為"name"的輸入字段,它將當(dāng)前日期顯示為預(yù)設(shè)值。這對(duì)於第一行來(lái)說(shuō)效果很好。然而,當(dāng)我動(dòng)態(tài)新增更多行時(shí),新的輸入欄位不會(huì)顯示預(yù)設(shè)的日期值。以下是我的目前程式碼設(shè)定:</p> <pre class="brush:html;toolbar:false;"><html> <body> <table class="table table-bordered"> <thead class="table-success" style="background-color: #3fbbc0;"> <tr> <th width="15%"><center>Service</th> <th width="5%"></th> <th> <button type="button" class="btn btn-sm btn-success" onclick="BtnAdd()">Add Item</button> </th> </tr> </thead> <tbody id="TBody"> <tr id="TRow" class="d-none"> <td><input type="text" name="name[]" id="name" value="<?php echo date("Y-m-d"); ?>"></td> <td class="NoPrint"> <button type="button" class="btn btn-success" style="line-height: 1;" onclick="BtnDel(this)">x</button> </td> </tr> </tbody> </table> <script type="text/javascript"> // Script to add dynamic rows in the table function BtnAdd() { var v = $("#TRow").clone().appendTo("#TBody"); $(v).find("input").val(''); $(v).find("input").autocomplete({ source: 'backend-script.php' }); $(v).removeClass("d-none"); $(v).find("th").first().html($('#TBody tr').length - 1); } function BtnDel(v) { $(v).parent().parent().remove(); $("#TBody").find("tr").each(function(index) { $(this).find("th").first().html(index); }); } </script> </body> </html> </pre> <p>我需要一些關(guān)於如何使這些動(dòng)態(tài)建立的欄位也顯示當(dāng)前日期作為它們的預(yù)設(shè)值的指導(dǎo)。非常感謝您對(duì)我的學(xué)習(xí)計(jì)畫提供協(xié)助。 </p>
P粉409742142
P粉409742142

全部回覆(1)
P粉352408038

問(wèn)題似乎是在動(dòng)態(tài)建立新行時(shí),您將輸入欄位的值設(shè)為空字串。這就是為什麼新行不顯示當(dāng)前日期的原因。

您可以修改BtnAdd()函數(shù),將新輸入欄位的值設(shè)定為目前日期。您可以在JavaScript中這樣取得目前日期:

new Date().toISOString().split('T')[0].

Take a look:

function BtnAdd() {
  /*Add Button*/
  var v = $("#TRow").clone().appendTo("#TBody") ;
  var currentDate = new Date().toISOString().split('T')[0]; // Get the current date
  $(v).find("input").val(currentDate); // Set the value of the new input field to the current date
  $(v).find("input").autocomplete({ source: 'backend-script.php' });
  $(v).removeClass("d-none");
  $(v).find("th").first().html($('#TBody tr').length - 1);
} 
最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板