我想将一个字符串值放在一个数组中,根据它们相对于所有具有类名的元素的位置。我得到了我想要使用的索引数组,现在我想使用每个索引值来选择适当的值。如何从循环内部选择特定的jquery元素值?
$(function()
{
$("#date").datepicker();
$('input[name=date]').datepicker();
var dateInput = $("select[name='searchString']");
var theClassTime = $("input.TextBoxDate");
var checkedindex = [];
var classday = [];
$("input[name='selectedCourses']").each(function (i)
{
if (this.checked)
{
// this works fine
checkedindex.push(parseInt(i));
// this is where I’m trying to select values based on index.
var dayofclass = $(".TextBoxDate:eq(" + checkedindex[i] + ")");
classday.push(dayofclass);
alert(classday);
}
});
});
说checkedindex有值:2,3,9在checkedindex的索引0处的含义是2,在1 = 3和在2 = 9。我想用2,3和9做这样的事情:
var dayofclass = $(".TextBoxDate:eq(" + checkedindex[i] + ")");
我在做什么错在这里?
你有没有试过循环选择的课程。然后在你的if语句中if(this.checked)var addVal = this.innerhtml(); classday.push(addval);. –
我上面写的基本上是在选中的课程中获得教学输入的价值。存储该值然后将其添加到数组中。我不确定你是否试图从复选框列表中获取html或索引 –