简体   繁体   English

jQuery UI MultiSelect Widget-如何使第一项取消选中?

[英]jQuery UI MultiSelect Widget-How to make First item Uncheked?

I am implementing this JQuery UI multiselect from http://www.erichynds.com/jquery/jquery-ui-multiselect-widget/ 我正在从http://www.erichynds.com/jquery/jquery-ui-multiselect-widget/实现此JQuery UI multiselect

When I'm trying to validate my single select dropdownbox , even if nothing's been selected and the "Please Select" is visible, it still thinks that the first item in the list is the selected one. 当我尝试验证我的单个选择dropdownbox框时,即使未选择任何内容并且“请选择”可见,它仍认为列表中的第一项是选中的项。

$("#ddlAlternativeCode option:selected").val() just gets back the value of my first item in the dropdown. $("#ddlAlternativeCode option:selected").val()刚从下拉列表中获取我的第一项的值。 I need it to be 0 or null . I need it to be 0 or null Can anyone help me? 谁能帮我?

You dont need to write "option:selected" in the $("#ddlAlternativeCode option:selected").val() 您不需要在$(“#ddlAlternativeCode option:selected”)。val()中编写“ option:selected”

Try this instead: 尝试以下方法:

$("#ddlAlternativeCode").val();

You should be able to see it working by adding this following alert which should show NULL if nothing is selected: 通过添加以下警报,您应该能够看到它的工作状态;如果未选择任何内容,则该警报应显示NULL:

alert("value= "+$('#ddlAlternativeCode').val());

where the id is the id of the selector. id是选择器的ID。 If that doesn't work, your javascript has an error somewhere. 如果这不起作用,则您的JavaScript某个地方有错误。

The other way of collecting selected values with Eric's script is via the "GetChecked" method call on the API. 使用Eric的脚本收集所选值的另一种方法是通过API上的“ GetChecked”方法调用。 See example here: 在这里查看示例:

var array_of_checked_values = $("select").multiselect("getChecked").map(function(){
   return this.value;    
}).get();

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

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