0

こんにちは、このようなjqueryコードを使用しています

$(".selfont").change(function(event){

$('#dav').val();

window.location ='?davQ=' + $('#dav').val() + '&pathogenQ=' + $('#pathogen').val() + '&topicQ=' + $('#topicF').val() ;

});

各ドロップダウンボックスでユーザーが選択したドロップダウン値を保持したい。しかし、現時点では、値はユーザーが選択したものではなく、常に最初の値が表示されます。jqueryを使用してユーザーが選択した値でドロップダウンフィールドを設定するにはどうすればよいですか? 私を助けてください。

私の最初の選択ボックスのコードは以下のようなものです

<select name="dav" id="dav" style="width: 275px" class='selfont' >
<option value='' class=''>Select one</option>
                        <?php

                                $test = mysql_query("SELECT DISTINCT DataVersion FROM olivesdeptable ORDER BY DataVersion DESC");
                                 $i=1;
                                 while($numval=mysql_fetch_array($test))
                                 {
                                          print "<option value=\"".$numval['DataVersion']."\">".$numval['DataVersion']."</option>";
                                          $i=$i+1;
                                  }
                          ?>

                    </select>

値を選択しても、フィールドには「1 つ選択」と表示されます。

ドロップダウン フィールドの JavaScript コード

<script type="text/javascript">

if (document.getElementById("dav").selectedIndex < 1)
{
document.getElementById('pathogen').selectedIndex = "";
document.getElementById('pathogen').disabled = true;
}

if (document.getElementById("pathogen").selectedIndex < 1)
{
document.getElementById('topicF').selectedIndex = "";
document.getElementById('topicF').disabled = true;
}

if (document.getElementById("topicF").selectedIndex < 1)
{
document.getElementById('ind').selectedIndex = "";
document.getElementById('ind').disabled = true;
}

if (document.getElementById("ind").selectedIndex < 1)
{
document.getElementById('subind').selectedIndex = "";
document.getElementById('subind').disabled = true;
}

if (document.getElementById("subind").selectedIndex < 1)
{
document.getElementById('countryR').selectedIndex = "";
document.getElementById('countryRF').options.length = 0;
document.getElementById('countryRF').selectedIndex = "";
document.getElementById('countryR').disabled = true;
document.getElementById('countryRF').disabled = true;
}

</script>

値が更新されても、2 番目のドロップダウン ボックスが無効として表示されますか?

次のドロップダウン フィールドのマークアップは次のとおりです。

 <select name="pathogen" id="pathogen" style="width: 275px" class='selfont' >
    <option value=''>Select one</option>
                            <?php

                                    $test = mysql_query("SELECT DISTINCT Pathogen FROM olivesdeptable where DataVersion='$davQ' ORDER BY Pathogen ASC");
                                    $i=1;
                                     while($numval=mysql_fetch_array($test))
                                     {
                                              print "<option value=\"".$numval['Pathogen']."\">".$numval['Pathogen']."</option>";
                                              $i=$i+1;
                                      }
                              ?>

                    </select>

最初のドロップボックス値のみが機能し、次のドロップボックス値は URL に保存されますが、ページでは値が「1 つ選択」と表示されますか? 並べ替えにご協力ください

4

2 に答える 2

1
 $(document).ready(function () {
            $('#dav').val(getURLParameter('davQ'));

            $('#pathogenQ').val(getURLParameter('pathogenQ'));

            $('#topicQ').val(getURLParameter('topicQ'));

            $(".selfont").change(function (event) {
                 window.location = '?davQ=' + $('#dav').val() + '&pathogenQ=' + $('#pathogen').val() + '&topicQ=' + $('#topicF').val();
            });

            function getURLParameter(name) {
            return decodeURI((RegExp(name + '=' + '(.+?)(&|$)').exec(location.search) || [, null])[1]);
            }
        });
于 2012-05-14T09:06:47.383 に答える
0
<?php

  $test = mysql_query("SELECT DISTINCT DataVersion FROM olivesdeptable ORDER BY DataVersion DESC");
  $i=1;
  $selected = '';
  // make compare with the value you want to select with the parameter form url
  // here I assume $_GET['davQ'] holds the value to $numval['DataVersion']
  if($_GET['davQ'] == $numval['DataVersion']) $selected = 'selected';
  while($numval=mysql_fetch_array($test))
  {
     echo "<option value=\"".$numval['DataVersion']."\" $selected>".$numval['DataVersion']."</option>";
     $i=$i+1;
  }
?>
于 2012-05-14T09:01:57.700 に答える