Javascript 输入表单的少数字段不允许输入数据
我有一个表单,表单上有一个按钮(+符号),它附加了一行以插入值。在我的表单中,我可以在第一行的两个字段(Javascript 输入表单的少数字段不允许输入数据,javascript,html,forms,Javascript,Html,Forms,我有一个表单,表单上有一个按钮(+符号),它附加了一行以插入值。在我的表单中,我可以在第一行的两个字段(stationerytype和stationeryqty)上输入值。但是,一旦我通过单击加号按钮添加新行,我就无法在第二行的StaineryType字段中插入任何值,而可以在第二行的stationeryqty字段中插入值 我的代码是: <table class="table table-bordered" id="tb" > <tr
stationerytype
和stationeryqty
)上输入值。但是,一旦我通过单击加号按钮添加新行,我就无法在第二行的StaineryType
字段中插入任何值,而可以在第二行的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>
没有。
固定式
固定量
这看起来像是一个JS问题,而不是PHP问题。请确保您只添加与当前问题相关的标记。这是有争议的,因为您确实使用php循环来写出初始元素,也就是说我同意Magnus的观点,实际问题与php不太相关,因此标记与实际问题不符,您确定没有其他原因导致此问题吗。我在这里重新创造了你的环境。我确实需要修复一些语法问题,我认为这些问题在实际代码中并不存在,但它似乎按照预期工作。另外值得注意的是,php循环中的id=“stationeryqtyrecd”
将生成无效的html,因为id必须是唯一的,您可能需要类似于id=“stationeryqtyrecd”