简体   繁体   English

如何使用CSJS从xp:listBox收集值?

[英]How to collect values from xp:listBox with CSJS?

How can I collect via CSJS the selected value(s) in a xp:listbox control? 如何通过CSJS在xp:listbox控件中收集选定的值?

I tried the samples similar for checkboxes / radiobuttons/ input field but this does not give me the correct values in return. 我尝试过类似复选框/单选按钮/输入字段的示例,但这并没有给我正确的值。

http://celinainsurance.blogspot.se/2011/04/getting-setting-values-with-ssjs-and.html http://celinainsurance.blogspot.se/2011/04/getting-setting-values-with-ssjs-and.html

This is more a JavaScript question then an XPages one, so if you search Google/ SO for 'javascript get selected options select' you'll find plenty of examples for your question. 这是一个JavaScript问题,而不是XPages,因此,如果您在Google / SO中搜索“ javascript get selected options select”,则会找到很多示例问题。

That said, here's an example of the code you can use to get the selected options: 也就是说,这是可用于获取所选选项的代码示例:

var selected = [];
var lb = document.getElementById("#{id:yourListBoxId}");

for (var i=0; i<lb.options.length; i++) {
  var o = lb.options[i];
  if (o.selected) { selected.push(o.value); }
}

console.log(selected); 

我正在使用jQuery val()函数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM