下拉日历没有出现在 html 表中的新插入行中

阿德什·辛格

当我点击输入下拉日历来选择日期时,我有一个带有日历的表单输入字段。通过使用 javascript,我在表中插入了一个新行。行正在插入表中,但日期日历没有像上一行那样出现在新插入的行日期字段中。我正在使用以下代码

function addRow() {
  var table = document.getElementById("mintable");
  var rowCount = parseInt(document.getElementById("minRows").value);
  var rowInsert = parseInt(document.getElementById("sizemin").value);
  var row = table.insertRow(rowInsert + 1);
  var cell1 = row.insertCell(0);
  var element1 = document.createElement("input");
  element1.type = "text";
  element1.id = "minenddate" + (rowCount);
  element1.className = "form-control";
  cell1.appendChild(element1);

  rowCount = parseInt(rowCount) + 1;
  document.getElementById("minRows").value = rowCount;
  document.getElementById("sizemin").value =
    parseInt(document.getElementById("sizemin").value) + 1;
}
$(function() {

  count = document.getElementById("minsize").value;
  i = 0;
  dateId = "datepicker2";
  for (i = 0; i <= (count + 1); i++) {
    dateId = "#datepicker2" + i;
    $(dateId).datepicker();

  }

});
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/7.0.0/normalize.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">

<input type="hidden" id="minsize" value="1">
<div class="">
  <table id="mintable" class="table table-bordered table-striped stripe hover row-border">
    <thead class="div-head">
      <tr>
        <th><b>Date</b></th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><input type="text" id='datepicker20' value="2018-08-09" class="form-control"></td>
      </tr>
    </tbody>
  </table>
  <input type="hidden" name="minRows" id="minRows" value='1'>
  <input type="hidden" id="sizemin" name="sizemin" value='1' />

</div>
<input type="submit" data-toggle="tooltip" title="Insert new horizon 
       " data-placement="top" class="btn btn-primary" id="button" value="Add Row" onClick="addRow()" />

古鲁普拉萨德·J·拉奥

您必须重新初始化datepicker动态添加的元素。

这是添加方法。

$('#'+element1.id).datepicker();

function addRow() {
  var table = document.getElementById("mintable");
  var rowCount = parseInt(document.getElementById("minRows").value);
  var rowInsert = parseInt(document.getElementById("sizemin").value);
  var row = table.insertRow(rowInsert + 1);
  var cell1 = row.insertCell(0);
  var element1 = document.createElement("input");
  element1.type = "text";
  element1.id = "minenddate" + (rowCount);
  element1.className = "form-control";
  cell1.appendChild(element1);
  $('#' + element1.id).datepicker(); //add this line to initialize
  rowCount = parseInt(rowCount) + 1;
  document.getElementById("minRows").value = rowCount;
  document.getElementById("sizemin").value =
    parseInt(document.getElementById("sizemin").value) + 1;
}
$(function() {

  count = document.getElementById("minsize").value;
  i = 0;
  dateId = "datepicker2";
  for (i = 0; i <= (count + 1); i++) {
    dateId = "#datepicker2" + i;
    $(dateId).datepicker();
  }

});
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script src="resources/js/jquery.dataTables.min.js"></script>
<script src="resources/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/7.0.0/normalize.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<input type="hidden" id="minsize" value="1">
<div class="">
  <table id="mintable" class="table table-bordered table-striped stripe hover row-border">
    <thead class="div-head">
      <tr>
        <th><b>Date</b></th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><input type="text" id='datepicker20' value="2018-08-09" class="form-control" /></td>
      </tr>
    </tbody>
  </table>
  <input type="hidden" name="minRows" id="minRows" value='1'>
  <input type="hidden" id="sizemin" name="sizemin" value='1' />

</div>
<input type="submit" data-toggle="tooltip" title="Insert new horizon 
       " data-placement="top" class="btn btn-primary" id="button" value="Add Row" onClick="addRow()" />

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

我的表单字段没有出现在html文件中

图像没有出现在 html 中,它看起来像是坏了

为什么我的 vtt 字幕没有出现在我的 html5 视频中?

为什么方块没有出现在这个 socket.io html 文件中?

如果它们的值出现在列表中但不在表中,如何插入行;如果它们的值没有出现在列表中但在表中,如何删除行?

CMFCColorButton没有出现在MFC类向导下拉菜单中

滚动条没有出现在 CSS 的下拉列表中

出现在html li中的箭头

我的 class=float 没有在代码中浮动,并且整个 html 没有通过 Google Tagmanager 出现在网站上

colspan/rowspan 未按预期出现在 HTML 表中

Oracle:使用现有表中的值和新值插入行

为什么数据出现在突变上,但没有出现在查询中?

我的css样式中只有一些出现在我的html文件中

EditText没有出现在模拟器中

int 80没有出现在汇编代码中

吐司通知没有出现在MVC 4中

UITableView没有出现在ViewController中

图例没有出现在ggplot中

ubuntu 启动没有出现在 grub 菜单中

QRectF没有出现在我的QGraphicsScene中

newTrigger AppsScript没有出现在UI中

JScrollPane没有出现在JFrame中

NestedScrollView没有出现在AlertDialog中

Entry() 没有出现在我的程序中

imageView没有出现在模拟器中

Primefaces:ContextMenu没有出现在overlayPanel中

DividerItemDecoration没有出现在RecyclerView中

Bxslider没有出现在选项卡中

IconMenu没有出现在material-ui中