[英]Javascript cant increase value of select
So i am having some issues with increasing a Selects NAME="" value.. 所以我在增加Selects NAME =“”值时遇到了一些问题。
I am working on a loop where everytime it goes arround the value must end with a higher number... 我正在一个循环中,每次循环时,值都必须以更高的数字结尾...
the following lines which don't work are : 以下行无效:
$('select[name="Ma_uurVan'+ xy + '"]').attr("name", "Ma_uurVan" + [y]);
$('select[name="Ma_uurTot'+ xy + '"]').attr("name", "Ma_uurTot" + [y]);
Hope anyone of you could spot my mistake 希望你们中的任何人都能发现我的错误
html : html:
<tr name="Ma_uren0">
<td>
<select name="Ma_uurVan0">
<option value="08:00">08:00</option>
<option value="08:30">08:30</option>
<option value="09:00">09:00</option>
</select>
</td>
</tr>
javascript : javascript:
var i = 0;
var x = 0;
var y = 1;
var xy = 1;
// functie voor maandag
$('[name=Ma_addRow]').click(function (){
if(x < 1)
{
$('[name="Ma_uren0"]').clone().attr('name', 'Ma_uren'+[y]).insertAfter('[name="Ma_uren0"]');
$('select[name="Ma_uurVan0"]').find('select').attr('name', 'Ma_uurVan' + [y] );
$('select[name="Ma_uurTot0"]').attr('name', 'Ma_uurTot' + [y] );
x++;
y++;
}else
{
$('[name="Ma_uren0"]').clone().attr('name', 'Ma_uren'+[y]).insertAfter('[name="Ma_uren'+[xy]+'"]');
$('select[name="Ma_uurVan'+ xy + '"]').attr("name", "Ma_uurVan" + [y]);
$('select[name="Ma_uurTot'+ xy + '"]').attr("name", "Ma_uurTot" + [y]);
y++;
xy++;
}
});
hope anyone could figure it out.. 希望任何人都可以解决。
I think the mistake is because of you increase xy
every time and you initialize the variable to 1. So $('select[name="Ma_uurVan'+ xy + '"]')
always return null. 我认为错误是因为每次您都增加
xy
并将变量初始化为1。因此$('select[name="Ma_uurVan'+ xy + '"]')
始终返回null。
Last, I think you use 3 variables while 2 should be enough since y
is always equal to xy
. 最后,我认为您使用3个变量,而2个就足够了,因为
y
始终等于xy
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.