[英]Trigger function on chosen-select multiple
I need to increase or decrease the cost on selecting multiple options from a jquery multiple chosen select. 我需要增加或减少从jquery多选所选中选择多个选项的成本。 The cost will increase on selecting options and will decrease by removing the option. 选择选项后成本会增加,删除选项会降低成本。
<select multiple="" class="chosen-select" id="form-field-select-4" data-placeholder="Choose a Department...">
<option value="Management">Senior Management</option>
<option value="Legal">Legal</option>
<option value="Operations">Operations</option>
<option value="Administration">Administration</option>
<option value="R&D">R&D</option>
</select>
The cost will increase if end user chooses more departments and will decrease by removing the chosen department. 如果最终用户选择更多部门,成本将增加,并且通过删除所选部门将减少成本。
How can I trigger a function on change of this multiple select and how do I get if end user has added a new option or removed a chosen one? 如何在更改此多项选择时触发功能,如果最终用户添加了新选项或删除了所选项,我该如何获得?
You can use option:selected
to get the selected options and use them to calculate the amount on change of selection of select. 您可以使用option:selected
以获取所选选项,并使用它们来计算选择更改时的更改量。 The will automatically remove the deselected options
being returned by collection and you do not have to remember what is deselected and selected. 将自动删除集合返回的取消选择的options
,您不必记住取消选择和选择的内容。
$("#form-field-select-4 option:selected")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.