问题描述
朋友,
我创建了一个动态表,默认情况下会在其中创建新索引,但是当我要获取对象值的特定索引的值时,它将始终采用该对象的第一个索引值.
这是代码
hi friends,
I have made a dynamic table in which new index is created by default but while i am going to fetch the value of particular index of object value then it always taking the first index value of that objects.
Here is the code
<head>
<script language="javascript" src="js/jquery.min.js"></script>
<SCRIPT>
RowCount=1;
stat=false;
function AddRow()
{
jQtable=$('#SaleTable');
jQtable.each(function()
{
var LastRow="<TR><TD align=center><INPUT TYPE='text' name='Slno_"+RowCount+"' id='Slno_"+RowCount+"' size=1></TD><TD align=center><INPUT type='checkbox' name='in_travel_"+RowCount+"' ID='in_travel_"+RowCount+"' value='in_terval' size=10></TD><TD align=center><INPUT style='text-align:right' type='TEXT' name='date_"+RowCount+"' ID='date_"+RowCount+"' size=10></TD><TD align=center><textArea name='cities_visit_"+RowCount+"' ID='cities_visit_"+RowCount+"' cols=10></textArea></TD><td align=center><select id='reimbursement_"+RowCount+"' name='reimbursement_"+RowCount+"'><option selected='selected' value='None'>--None--</option><option value='DA'>DA</option><option value='Ticket'>Ticket</option><option value='Misc'>Misc</option></select></td><TD align=center><textArea name='Remark_"+RowCount+"' ID='Remark_"+RowCount+"' cols=10></textArea></TD><TD align=center><INPUT style='text-align:right' type='checkbox' name='bills_"+RowCount+"' ID='bills_"+RowCount+"' size=10></TD><TD align=center><INPUT style='text-align:right' type='submit' name='submit_"+RowCount+"' ID='submit_"+RowCount+"' onclick='getvalue()' value='Submit' size=10></TD><TD align=center></TR>";
$(this).append(LastRow);
});
RowCount++;
}
function removeTableRow()
{
jQtable=$('#SaleTable');
if(RowCount > 1)
{
jQtable.each(function()
{
if($('tbody', this).length > 0)
{
$('tbody tr:last', this).remove();
}
else
{
$('tr:last', this).remove();
}
});
RowCount--;
}
}
function getvalue()
{
////var inp= $('input:radio[name=PatientPreviouslyReceivedDrug]:checked').val();
alert(RowCount);
var sl= $('input:text[name=Slno_+ RowCount]').val();
alert(sl);
var in_tra= $('input:checkbox[name=in_travel_+ RowCount]:checked').val();
alert(in_tra);
//var slect=$('input:select[name=reimbursement_+ RowCount]:selected').val();
var slect=$("#reimbursement_+ RowCount option:selected").val();
alert(slect);
var val= $('input:text[name=Slno_2]').val();
alert(val);
}
</script>
</head>
<body>
</body>
在这里,变量RowCount每次都会获取一个新值,但是当我要在函数getvalue()上访问它时,
Alert(RowCount);
每次都在改变价值
但
的价值
var sl = $(''input:text [name = Slno_ + RowCount]'').val(); < -----这里总是一样
因此,问题是如何更改Slno _ +<-RowCount->的值.这个变量
这样就好像RowCount = 2一样,变量应该是slno_2
谢谢
here,variable RowCount getting a new value every time but when i am going to access it on function getvalue()
Alert(RowCount);
value is changing in every time
but the value of
var sl= $(''input:text[name=Slno_+ RowCount]'').val(); <----- here is always same
So the question is how to change the value of Slno_+<-- RowCount--> this varable
So that it take as if RowCount=2 then variable should be slno_2
Thanks
推荐答案
这篇关于如何在变量中添加一个增量值.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!