开发者

Unselecting Dropdown Checklist from dropdown-check-list.googlecode.com

开发者 https://www.devze.com 2023-02-18 14:11 出处:网络
I am trying 开发者_如何转开发to select/unselect items individually in a Dropdown Checklist plugin for jQuery.

I am trying 开发者_如何转开发to select/unselect items individually in a Dropdown Checklist plugin for jQuery.

The plugin is : dropdown-check-list.googlecode.com

I have tried this but it doesn't work :

$('#mylist option').each(function() {
    $(this).attr('selected',false);
    $('#mylist'+i).attr('selected',false);
}

Where i is an incremented integer. I have also tried with removeAttr before attr...

Anyone has an idea how to accomplish this ?

I have tried to implement the following, to no avail :

Dropdown CheckList generates two basic components that are inserted into the document. There is a control wrapper which is positioned in place of the original selector and acts like the item on the page. And there is the drop-down wrapper which is only visible when the control wrapper is 'open' and is positioned under the control.

Both of these items are assigned an id, which you can use in other jQuery processing to locate and alter the items.

Control Wrapper The control wrapper has a generated id of the form "ddcl-XXX", where the XXX is either 1) the assigned id of underlying , or 2) an incrementing counter when the has no id assigned. Drop-down Wrapper The drop-down wrapper has a generated id of the form "ddcl-XXX-ddw", where the XXX matches the XXX of the control wrapper.

These ids must be unique and Dropdown CheckList assumes no other elements on the page have an id that conflicts.

Many thanks for your help !


Try this,

$("#mylist").val("");
$("#mylist").dropdownchecklist("refresh");


I found the answer.

Actually, you need to destroy the component.

See below :

$('#mylist').dropdownchecklist('destroy');
 $('#mylist option').each(function() {
    $(this).attr('selected',false);
 });
$("#mylist").dropdownchecklist();


I noticed that i was not defined, you need to initiate it in the function you pass to the each loop:

$('#mylist option').each(function(i, el){
    $(this).attr('selected',true);
    $('#mylist'+i).attr('selected',true);
});

BTW, will #mylist1 & #mylist2 actually exist? Why are you trying to check them if they are lists, not options?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号