开发者

jQuery function called multiple times, only remove once

I have a function that removes all of the options from a drop down box except for the first one. This function is updated every time another drop down box is changed, and appends other elements depending on what the other drop down is selected. My problem is I always want to keep the first item, but it removes it whenever I call the function more than the first time. What is 开发者_运维技巧a better way of doing this?

function updateMountingMethod(){

 var selectedVal = $('#attrib-13 option:selected').text().split(" ")[0];
 var optionChildren = $("#attrib-7").children(":not(:first-child)").clone();

 $("#attrib-7").children(":not(:last-child)").remove();


  $.each(optionChildren, function(){


  if ($(this).text().split('|')[1]!=undefined)
   {
   var values = $(this).text().split('|')[1];

   if(values.substring(1,3) == selectedVal)
   {

    $("#attrib-7").append($(this).text($(this).text().split("|")[0]+" "+$(this).text().split("|")[2]));
   }
   }


 })
}


document.getElementByID('attrib-7').options.length = 1;

this removes all but the first option from the select list. not sure the JQuery equivelent.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜