【发布时间】:2016-09-20 09:40:14
【问题描述】:
我有许多表单,有两个下拉选项名称和值,我希望选择名称选项作为数组中的一个变量,就像这样。
for (i = 0;i<noOfElements;i++)
{
var resultHtml = theModule.getHtml("rowformtemplate", {});
//load html of form with fields **name** and **value** as dropdown
$(section).append(resultHtml);
//append html to a div
var optValue = namearray[i];
//from list of optons this value should be selected
var form = $(section).find(".row-template");
//find all forms in the section
var row= form[form.length-1];
//select latest form
//How to select name field "name" of current row and set it to be optvalue which is a variaable something like this. but it selects name field of all form and sets it to optValue
$("select[name^='name'] option[value=" + optValue + "]").attr("selected","selected");
}
【问题讨论】:
-
几行后我停止阅读,请发布一些代码和适当可读的段落。
标签: javascript jquery