0
的指数I有一个小的这样的代码:得到在HTML(jQuery的)阵列状名称属性
<div class="question_wrapper">
<input type="text" class="textinput_questions new_question" name="new_question[1][]">
<input type="checkbox" class="radioinput" name="new_questionActive[]">
</div>
我生成在一个循环中,工作正常这些输出。 name="new_question[1][]"
中的硬编码1
将上升到3,所以我在这种模式下有3个索引。
现在,我想运行通过jQuery的AJAX请求,它看起来像这样:
$('.new_question').each(function() {
// for each added question, we call a script which then inserts the new questions
console.log(this);
});
到目前为止是这种情况,为正确的元素在我的控制台打印。但是,因为我需要索引的第一级,所以我需要以某种方式得到该值,因为这将是一个将在稍后传递给上述ajax函数的参数表。
要再次澄清:
我想通过所有问题进行迭代。对于每个问题,我使用这些特定值创建一个ajax-Request。我需要第一个数组索引(在上面的代码中写成1
。如果我想要3个问题,所有索引1和索引2都是索引2,那么我最终应该运行5次循环,定义在(假想的)可变categoryID
1(前3次运行)和2个在未来2点运行。
编辑
因为它似乎是有点不清楚,在1句的基本的东西:我需要从这样的模式得到数值(在我的案例中为1
):
<input type="text" class="textinput_questions new_question" name="new_question[1][]">
通过循环遍历each
-loop。
这是一个有点不清楚 - 你可以尝试以不同的方式提问?有几种方法可以解释这个 –
当然,我添加了一个编辑。也许这有助于澄清我的需求 – DasSaffe
您的意思是输入的价值?像'$('input [name =“new_question [1] []”])。val()' –