开发者

Need help with a JavaScript function to de-select items in jQuery DropdownChecklist

开发者 https://www.devze.com 2023-01-24 04:44 出处:网络
I\'m working on an ASP.Net webpage which开发者_如何学Python will use the jQuery Dropdown Checklist (http://code.google.com/p/dropdown-check-list/). I\'m fairly inexperienced with JavaScript and comple

I'm working on an ASP.Net webpage which开发者_如何学Python will use the jQuery Dropdown Checklist (http://code.google.com/p/dropdown-check-list/). I'm fairly inexperienced with JavaScript and completely new to jQuery.

Could anyone help me with a JavaScript function that de-selects items from a jQuery DropdownChecklist? It would need to accept a string, then de-select the item that matches that string.

Thanks in advance.


Try changing the original <select> element so that the item you want to deselect is no longer selected and then refresh the jQuery dropdown-checklist using the "refresh" command. Something like this (where selectID is the ID of the original <select> element and targetString is the content of the <option> you want to deselect):

function deselect(selectID, targetString){
  $("#"  + selectID + " option").each(function(){
      if($(this).text() === targetString) $(this).attr("selected", "");
  });
  $("#" + selectID).dropdownchecklist("refresh");
}


Following code deselects item and removes it from display.

document.clearSel = function(list,txt){
  var ele=document.getElementById(list);
  for(i=0; i < ele.options.length; i++ ) {  
    if (ele.options[i].selected && (ele.options[i].text == txt) && 
                                      (ele.options[i].value != "")) {
        var val=ele.options[i].value;
        $("div#ddcl-" + list +"-ddw input[value='"+val+"']").each(function(){
            $(this).attr("checked",false);
            var spSel="span#ddcl-" + list +" span.ui-dropdownchecklist-text";
            var spTxt=$(spSel).text();          
            $(spSel).text(spTxt.replace(txt+",",'').replace(txt,''));
        });
     }
  } 
}

document.clearSel("s8","Low");

I got "div#ddcl--ddw input[value='']" and "span#ddcl- span.ui-dropdownchecklist-text" selectors after examining demo page for drop down check list

PS:- I've trie $("#" + list).dropdownchecklist("refresh"); but I am not able to refresh the text;

0

精彩评论

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