<select> only shows first char of selected option

前端 未结 7 888
予麋鹿
予麋鹿 2020-12-01 02:08

I have a standard select box which I\'m populating using jquery by appending options, but for some reason IE9 only shows the first character of the selected option. Needless

相关标签:
7条回答
  • 2020-12-01 02:45

    Adding couple of lines the following places (marked in bold as **) in render function of the selectDirective in angular.js worked fine for me. I am looking if there is any other possible solution other than patching angularJS or the forEach given below?

    if (existingOption.label !== option.label) {
      lastElement.text(existingOption.label = option.label);
      **lastElement.attr('label', existingOption.label);**
    }
    

    and

      (element = optionTemplate.clone())
          .val(option.id)
          .attr('selected', option.selected)
          .text(option.label);
      **element.attr('label', option.label);**
    

    The issue was the label attribute of HTMLOptionElement is not the same as the text attribute if label is blank in IE.

    This can be seen verified by adding the following code after the screen has loaded and looking at the web console of FF and IE to see the difference. If you uncomment the last line where the label is set to text it works fine. Alternatively patch angular.js as above.

    // This is an IE fix for not updating the section of dropdowns which has ng-options with filters
    angular.forEach($("select"), function (currSelect) {
        console.log("1.text ", currSelect.options[currSelect.selectedIndex].text);
        console.log("1.label ", currSelect.options[currSelect.selectedIndex].label);
        //console.log("1.innerHTML ", currSelect.options[currSelect.selectedIndex].innerHTML);
        //console.log("1.textContent ", currSelect.options[currSelect.selectedIndex].textContent);
        //console.log("1.cN.data ", currSelect.options[currSelect.selectedIndex].childNodes[0].data);
        //console.log("1.cN.nodeValue ", currSelect.options[currSelect.selectedIndex].childNodes[0].nodeValue);
        //console.log("1.cN.textContent ", currSelect.options[currSelect.selectedIndex].childNodes[0].textContent);
        //console.log("1.cN.wholeText ", currSelect.options[currSelect.selectedIndex].childNodes[0].wholeText);
        //console.log("1. ", currSelect.options[currSelect.selectedIndex], "\n");
    
        //currSelect.options[currSelect.selectedIndex].label = "xyz";
        //currSelect.options[currSelect.selectedIndex].label = currSelect.options[currSelect.selectedIndex].text;
    });
    
    0 讨论(0)
提交回复
热议问题