javascript - INPUT 表单的少数字段不允许输入数据
问题描述
我有一个表单,表单上有一个按钮(+符号),它附加一行以插入值。在我的表单中,我可以在第一行的两个字段(stationerytype
和stationeryqty
)上输入值。但是,一旦我通过单击加号按钮添加新行,我就无法在第二行的字段中插入任何值,staionerytype
而我能够在stationeryqty
第二行的字段中插入值。
我的代码是:
<table class="table table-bordered" id="tb" >
<tr class="tr-header">
<th class= "col-md-1" align="centre">Sl.No.</th>
<th class= "col-md-6" align="centre">STATIONARY TYPE</th>
<th class= "col-md-4" align="centre">STATIONARY QUANTITY</th>
<th class= "col-md-1"><a href="javascript:void(0);" style="font-size:18px;" id="addMore" title="Add More Stationery"><span class="glyphicon glyphicon-plus"></span></a></th>
</tr>
<tr>
<?php
for($i=1;$i<=1;$i++)
{
?>
<td><input type="text" style="text-decoration: none" name="slno" value= "<?php echo $i; ?>" ></td>
<td><input type="text" style="text-decoration: none" name="stationerytype" ></td>
<td><input type="number" name="stationeryqtyrecd" id="stationeryqtyrecd" min="0"></td>
<td><a href='javascript:void(0);' class='remove'><span class='glyphicon glyphicon-remove'></span></a></td>
</tr>
<?php }?>
</table>
<button type="submit" name="add" class="btn btn-info" align="middle" >ADD </button>
<script>
var max = 4;
var count = 1;
$(function(){
$('#addMore').on('click', function() {
if(count <= max ){
var data = $("#tb tr:eq(1)").clone(true).appendTo("#tb");
data.find("input").val('');
debugger;
data.find("input")[0].value=++count;
}else{
alert("Sorry!! Can't add more than five samples at a time !!");
}
});
$(document).on('click', '.remove', function() {
var trIndex = $(this).closest("tr").index();
if(trIndex>1) {
$(this).closest("tr").remove();
} else {
alert("Sorry!! Can't remove first row!");
var trIndex = $(this).closest("tr").index();
if(trIndex>1) {
$(this).closest("tr").remove();
count--;
// get all the rows in table except header.
$('#tb tr:not(.tr-header)').each(function(){
$(this).find('td:first-child input').val(this.rowIndex);
})
}
});
});
</script>
</div>
解决方案
推荐阅读
- c - 获取鼠标按钮状态非阻塞linux
- sql - Laravel updateOrCreate on hasOne 具有不同值的关系
- python - 获取 pymongo.errors.CursorNotFound: cursor id "..." not found
- javascript - 为什么我的 Firestore 权限不起作用?
- python - 按键过滤字典
- python - 在 for 循环中递增计数器以对简单数组求和
- git - 如何从 Heroku 保存文件?
- javascript - 参数类型与 UrlFetchApp 有效负载不匹配
- c# - 使用 C# 编辑 WAV 文件
- asp.net-core - 我们如何使用实体框架核心 3.1 连接 Hana 数据库?