我想將一個字符串值放在一個數組中,根據它們相對於所有具有類名的元素的位置。我得到了我想要使用的索引數組,現在我想使用每個索引值來選擇適當的值。如何從循環內部選擇特定的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或索引 –