在jqxListBox({})中向CheckBox添加ID和值

时间:2015-05-01 02:54:13

标签: jquery jqwidget

我需要在列表框中的CheckBoxes中添加ID

<input type=”checkbox” name=”vehicle” id = 1>Code</br>
<input type=”checkbox” name=”vehicle” id = 2>Select

一旦我选择CheckBox并且我需要获取CheckBox ID,我也可以勾选CheckBox基于ID如何做????

但这里不能添加

var source = [
"Affogato",
"Caffé Latte"];

// Create a jqxListBox
$(“#jqxListBox”).jqxListBox({
source: source,
theme: ‘energyblue’,
width: ’200px’,
height: ’250px’,
checkboxes:true
});

1 个答案:

答案 0 :(得分:1)

http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxlistbox/index.htm?(arctic)#demos/jqxlistbox/checkboxes.htm

您可以使用checkChange事件,在您的情况下,源应该有两个值(1 - displayMember,2 - valueMember):

var source = [{
  vehicle: "Affogato",
  id: 122
}, {
  vehicle: "Americano",
  id: 156
}, {
  vehicle: "Bicerin",
  id: 1023
}, {
  vehicle: "Breve",
  id: 4567
}];

$("#jqxListBox").jqxListBox({
  source: source,
  displayMember: "vehicle", 
  valueMember: "id",
  checkboxes: true
});

$("#jqxListBox").on('checkChange', function (event) {
  var args = event.args;
  // get new check state.
  var checked = args.checked;
  // get the item and it's label and value fields.
  var item = args.item;
  var itemLabel = item.label;
  var itemValue = item.value;
});

尝试此操作以提供帮助:https://jsfiddle.net/charlesrv/YnqPP/31/