我有两个g:选择要在单击图像时添加到多选列表的组合框。
这是javascript中的函数:
function addToList(list,firstOpt, secOpt)
{
var y = document.createElement('option');
y.text = firstOpt + ' - ' + secOpt;
y.value = firstOpt+'-'+secOpt;
var elSel = document.getElementById(list);
try {
elSel.add(y, null); // standards compliant; doesn't work in IE
}
catch(ex) {
elSel.add(y); // IE only
}
}
我认为问题出现在实际按钮中:
<img src="${resource(dir:'images',file:'arrow.png')}" onclick="addToList('BList','first','second')"/>
当我点击它时,“first - second”被添加到列表中,而不是g:select框的实际值。我也试过${first}
和${second}
,但没有运气。
非常感谢任何帮助,谢谢!
答案 0 :(得分:1)
您没有任何代码可以检索第一个和第二个选择列表的值。
你可能需要这样的东西:
function addToList(destinationList, sourceList1Id, sourceList2Id) {
// your select lists will need ids
// e.g. <g:select id="listOneId" .../>
var list1 = document.getElementById(sourceList1Id);
var list2 = document.getElementById(sourceList2Id);
var list1value = list1.options[list1.selectedIndex].value;
var list2value = list2.options[list2.selectedIndex].value;
// the rest of your addToList() function, replacing 'firstOpt'
// and 'secondOpt' with 'list1value' and 'list2value' respectively
// ...
}
然后您可以使用以下选项:
<!-- sources -->
<g:select id="fooList" .../>
<g:select id="barList" .../>
<!-- destination -->
<g:select id="bazList" .../>
<img ... onclick="addToList('bazList', 'fooList', 'barList');"/>