首页 > 解决方案 > 如何根据选择的其他选择选项更改选择选项?

问题描述

我需要获取选择时生成的 pdf 路径文件:

     1- Type document
     2- Date
     3- Unity
    
    Type: 1 - 2 - 3
    Unity: A - B - C
    Date: yyyy/m/d

这是我应该管理信息的代码,所有数据都使用 cookie 存储。

这是 PHP 文件 - file.php:

<select id="diretorioArquivo" name="diretorioArquivo" class="" onChange=""abrir.location = options[selectedIndex].value">
      <option class="dropdown-item" selected disabled>Selecione um arquivo...</arquivo>
    
    <?php
    $data_unidade = $_COOKIE['data_unidade'];
    $tipo_arquivo = $_COOKIE['tipo_arquivo'];
    $id_unidade = $_COOKEI['id_unidades'];
    
    $urlPdf = 'http://localhost'.$data_unidade.'&tipo_arquivo='.$tipo_arquivo.&unidade_id='.$id_unidade;
    $recolhePdf = file_get`enter code here`_contents($urlpdf);
    $resultPdf = json_decode($recolhePdf);
    foreach($resultPdf as $pdf) {
    ?>
    
       <option id="<?php echo $pdf->id. ?>" value="localhost/arquivos/<?php echo $pdf->caminho; ?>"
       class=""<?php echo $pdf->caminho; ?></option>
    <?php
    }
    ?>
    </select>

    <!-- USING JQUERY -->
    <script>
      $('#diretorioArquivo').on('change', function() {
        var src=$(this).find('option:selected').val();
        $('#abrir').attr('src', src);
      });
    </script>

标签: phpjqueryjsonajaxapi

解决方案


推荐阅读