如何在IE中使用JQuery隐藏和显示下拉列表的选项

时间:2016-01-27 12:52:40

标签: javascript jquery internet-explorer

所以我尝试this让它运转起来。它在Firefox和Chrome上运行良好,但并不像往常一样在IE上运行。关于Javascript函数的想法是我在第一个选项框中查看并查看它何时被更改。更改后,它应该获取选项框的值并在第二个中查找它。然后只显示具有相同值的选项。

PHP代码:

<label style="width:100px;float:left;">f&uuml;r das Revier:*</label>
    <select class="required"  id="reviernummer" style="width:240px;"name="verhaltenscode" ' >
    <?php $selected = $arrayAktuellerDatensatz['verhaltenscode'];?>
        <option selected ="selected" value="<?php echo $selected; ?>"><?php echo $selected; ?></option>
        <?php loadselect('kataster', 'Fischereibuchzahl', 'Fischereibuchzahl');?>
    </select><br />

    <select class="required" id="verhaltenscode" style="width:240px;" name="verhaltenscode">
        <?php $selected = $arrayAktuellerDatensatz['verhaltenscode_neu'];?>
        <option selected ="selected" value="<?php echo $selected; ?>"><?php echo $selected; ?></option>
        <?php loadselect('helpbrutstatus', 'Brutstatus', 'Brutstatus');?>

loadselect功能:

if ($tblname == 'kataster'){
    $query = "SELECT * FROM kataster";
    $result = mysql_query($query) or die(mysql_error());
    while($row = mysql_fetch_array($result)){
        $fieldvalue = $row['Fischereibuchzahl'];
        $fieldcaption = $row['Fischereibuchzahl'];
        $lat = $row['Benennung']?>
        <option title="<?php echo $lat; ?>" value="<?php echo $fieldvalue;?>"><?php echo $fieldcaption .'&nbsp;|&nbsp;'.$lat?></option> <?php
        }
    }
    else if ($tblname == 'helpbrutstatus'){

    $query = "SELECT * FROM helpbrutstatus" ;

    $result = mysql_query($query) or die(mysql_error());
    while($row = mysql_fetch_array($result)){
        $fieldvalue = $row['Fischereibuchzahl'];
        $status = $row['Fischereibuchzahl'];
        $fieldcaption = $row['Brutstatus']; ?>
        <option value="<?php echo $fieldvalue;?>" title="<?php echo $status;?>"  class="sorted">
        <?php echo $status."&nbsp;|&nbsp;".$fieldcaption?></option>  <?php
        }
}

Javascript功能:

reviernummer.onchange = function() {
  var look = $("#reviernummer").val();
  $("option[class='sorted']").each(function(index, val) {
    if ($(this).is('option') && (!$(this).parent().is('span')))
      $(this).wrap((navigator.appName == 'Microsoft Internet Explorer') ? '<span>' : null).hide();
  });
  $("option[title='" + look + "']").each(function(index, val) {
    if (navigator.appName == 'Microsoft Internet Explorer') {
      if (this.nodeName.toUpperCase() === 'OPTION') {
        var span = $(this).parent();
        var opt = this;
        if ($(this).parent().is('span')) {
          $(opt).show();
          $(span).replaceWith(opt);
        }
      }
    } else {
      $(this).show(); //all other browsers use standard .show()
    }
  });
};

0 个答案:

没有答案