久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<small id='7zHJt'></small><noframes id='7zHJt'>

        <bdo id='7zHJt'></bdo><ul id='7zHJt'></ul>

    1. <i id='7zHJt'><tr id='7zHJt'><dt id='7zHJt'><q id='7zHJt'><span id='7zHJt'><b id='7zHJt'><form id='7zHJt'><ins id='7zHJt'></ins><ul id='7zHJt'></ul><sub id='7zHJt'></sub></form><legend id='7zHJt'></legend><bdo id='7zHJt'><pre id='7zHJt'><center id='7zHJt'></center></pre></bdo></b><th id='7zHJt'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='7zHJt'><tfoot id='7zHJt'></tfoot><dl id='7zHJt'><fieldset id='7zHJt'></fieldset></dl></div>
      <legend id='7zHJt'><style id='7zHJt'><dir id='7zHJt'><q id='7zHJt'></q></dir></style></legend>
      <tfoot id='7zHJt'></tfoot>
      1. 根據(jù)另一個下拉列表填充下拉列表的最佳和最簡

        What#39;s the best and easiest way to Populate a dropdown based on another dropdown(根據(jù)另一個下拉列表填充下拉列表的最佳和最簡單的方法是什么)
          <tbody id='E3IHx'></tbody>
          <bdo id='E3IHx'></bdo><ul id='E3IHx'></ul>
          <legend id='E3IHx'><style id='E3IHx'><dir id='E3IHx'><q id='E3IHx'></q></dir></style></legend>
            • <tfoot id='E3IHx'></tfoot>

              1. <small id='E3IHx'></small><noframes id='E3IHx'>

                  <i id='E3IHx'><tr id='E3IHx'><dt id='E3IHx'><q id='E3IHx'><span id='E3IHx'><b id='E3IHx'><form id='E3IHx'><ins id='E3IHx'></ins><ul id='E3IHx'></ul><sub id='E3IHx'></sub></form><legend id='E3IHx'></legend><bdo id='E3IHx'><pre id='E3IHx'><center id='E3IHx'></center></pre></bdo></b><th id='E3IHx'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='E3IHx'><tfoot id='E3IHx'></tfoot><dl id='E3IHx'><fieldset id='E3IHx'></fieldset></dl></div>

                1. 本文介紹了根據(jù)另一個下拉列表填充下拉列表的最佳和最簡單的方法是什么的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  很簡單,我有一個動態(tài)填充數(shù)據(jù)的下拉菜單:

                  Very simply, I have one dropdown menu dynamically populated with data:

                  SQL 代碼

                  $querycourse = "SELECT course, COUNT(course) AS count FROM acme WHERE course IS NOT NULL GROUP BY course ";
                  $procc = mysqli_prepare($link, $querycourse);
                  $queryc =  mysqli_query($link, $querycourse) or die(mysqli_error($link));
                  

                  PHP 代碼

                  echo "<select name='course[]' value='' multiple='multiple' size=10>";
                              // printing the list box select command
                              echo "<option value=''>All</option>";
                              while($ntc=mysqli_fetch_array($queryc)){//Array or records stored in $nt
                              echo "<option value="$ntc[course]">"$ntc[course]"</option>";
                              /* Option values are added by looping through the array */
                              }
                              echo "</select>";// Closing of list box 
                  

                  我需要的是另一個下拉列表,其中填充了基于第一個下拉框中選擇的數(shù)據(jù).

                  What I need is another dropdown that is populated with data based on a selection from the first dropdown box.

                  我正在使用 MySQL、PHP、Javascript,也可以(一推)使用 jQuery.我沒有使用 Ajax 的經(jīng)驗.

                  I am using MySQL, PHP, Javascript and can also (at a push) use jQuery. I have no experience in Ajax.

                  有人愿意為我指出正確的方向嗎?!

                  Would anyone be kind enough to point me in the right direction?!

                  提前致謝,一如既往,

                  荷馬.

                  推薦答案

                  第一種和最好的方法(如果您有或可能有足夠的選項特定數(shù)據(jù))
                  使用 AJAX.我認為,與其他實現(xiàn)相同的方法相比,這是最簡單的方法.使用Jquery 實現(xiàn)AJAX.它讓 AJAX 變得輕而易舉!在這里,我為你分享我的一塊蛋糕 -

                  First and Best Method (If you have or may have enough option specific data)
                  Use AJAX. It is the easiest way, I think, compared to the other ways to implement the same. Use Jquery to implement AJAX. It makes AJAX a piece of cake! Here I share my piece of cake for you -

                  以下是您需要的大致完整代碼 -

                  Following is roughly the complete code you need -

                  • 像這樣在您的第一個選擇中調(diào)用一個 javascript 函數(shù) populateSecondDropdown() -

                  • Call a javascript function populateSecondDropdown() on your first select like this -

                      echo "<select  name='course[]' value='' multiple='multiple' size=10 onchange='populateSecondDropdown(this, 'http://yourprojectUrl','Any Subject');'>";
                              // printing the list box select command
                              echo "<option value=''>All</option>";
                              while($ntc=mysqli_fetch_array($queryc))
                              {//Array or records stored in $nt
                                  echo "<option value="$ntc[course]">"$ntc[course]"</option>";
                                  /* Option values are added by looping through the array */
                              }
                              echo "</select>";// Closing of list box 
                  

                2. 在populateSecondDropdown()函數(shù)內(nèi)部定義一個ajax調(diào)用 -

                3. Define an ajax call inside inside the populateSecondDropdown() function -

                  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
                  
                  <script  type="text/javascript">  
                      function populateSecondDropdown(object,baseUrl)
                      {
                          $.ajax({
                          type: "POST", 
                          url: baseUrl+"/ajax/fetchOptions.php", 
                          data: { id_option: $(object).val(), operation: 'get_subjects' },
                          dataType: "json",
                          success: function(data) 
                          {
                              //Clear options corresponding to earlier option of first dropdown
                             $('select#secondDropdown').empty(); 
                             $('select#secondDropdown').append('<option value="0">Select Option</option>');
                                     //Populate options of the second dropdown
                             $.each( data.subjects, function() 
                             {    
                                 $('select#secondDropdown').append('<option value="'+$(this).attr('option_id')+'">'+$(this).attr('option_name')+'</option>');
                             });
                             $('select#secondDropdown').focus();
                          },
                              beforeSend: function() 
                              {
                                  $('select#secondDropdown').empty();
                                  $('select#secondDropdown').append('<option value="0">Loading...</option>');
                              },
                              error: function() 
                             {
                                $('select#secondDropdown').attr('disabled', true);
                                $('select#secondDropdown').empty();
                                 $('select#secondDropdown').append('<option value="0">No Options</option>');
                            }
                          });
                       }
                  </script>
                  

                  • 最后是在 AJAX 處理器文件 fetchOptions.php 中獲取第二個下拉選項的查詢.您可以在此處使用 $_POST['id_option'] 來獲取其下的選項.此處的數(shù)據(jù)庫查詢應獲取每個選項的 option_idoption_name 字段(正如 $.each 中的 jquery 代碼所預期的那樣)并返回一個json 編碼的數(shù)組是這樣的:-

                    • And finally the query to fetch 2nd dropdown's options in the AJAX processor file fetchOptions.php. You can use $_POST['id_option'] here to fetch the options under it. The database query here should fetch the option_id and option_name fields for every option (as expected by the jquery code inside $.each) and return a json encoded array like this:-

                      return json_encode(array("subjects" => $resultOfQuery));
                      

                    • 第二種方法(僅使用 javascript)

                      • 獲取按第一個下拉列表的字段分組的第二個下拉列表的所有數(shù)據(jù).例如.讓我們學習第一個下拉菜單中顯示的課程和第二個顯示的課程下的科目

                      • Fetch all the data for the second dropdown grouped by the field of the first dropdown. E.g. let's take courses displayed in the first dropdown and subjects under courses displayed in the 2nd

                      • 創(chuàng)建第二個下拉列表的所有選項.在創(chuàng)建如下選項時分配與課程相同的課程:-

                      • Create all the options of the 2nd dropdown. Assign classes equal to the courses while creating the options like this:-

                      $querycourse = "SELECT course, subject FROM subjects WHERE subject IS NOT NULL GROUP BY course ";
                      $procc = mysqli_prepare($link, $querycourse);
                      $queryc =  mysqli_query($link, $querycourse) or die(mysqli_error($link));
                      
                      echo "<select  name='subjects[]' value='' multiple='multiple' size=100>";
                      echo "<option value=''>All</option>";
                                  while($ntc=mysqli_fetch_array($queryc))
                                  {//Array or records stored in $nt
                                      echo "<option value="$ntc[subject]" class="$ntc[course]">"$ntc[subject]"</option>";
                                  }
                                  echo "</select>";
                      

                    • 然后為第一個下拉列表定義 onchange="displaySubjectsUnderThisCourse(this);" 并編寫此 javascript :-

                    • Then define onchange="displaySubjectsUnderThisCourse(this);" for the first dropdown and write this javascript :-

                       function displaySubjectsUnderThisCourse(object)
                       {
                           var selectedCourse = $(object).val();
                          //Display the options with class = the selected option from first dropdown
                          $("."+selectedCourse).removeClass("hidden"); //define a class hidden with display:none;
                      
                         $('option:not(.selectedCourse)').hide();  // hide all options whose class is other than selectedCourse - Not sure whether this will work or not, though
                      
                        //Deselect any previous selections
                        //If single option selection is allowed
                        $('select#secondDropdown option').attr('selected', false); 
                        // or following if multiple selection is allowed (needed for IE)
                        $('select#secondDropdown option').attr('selectedIndex', -1); 
                      
                      
                      }
                      

                      這里的基本思想是隱藏/顯示選項組,但我的代碼可能有錯誤.

                      The basic idea here is to hide/display option groups but my code may have errors.

                      最后,請注意,第二種方法(獲取所有選項值)只有在您的數(shù)據(jù)量有限并且非常確定將來數(shù)據(jù)量總是會減少的情況下才會更好.但是,由于沒有人能夠?qū)ξ磥砣绱舜_定,因此建議始終使用 AJAX 方法.

                      Finally, please note, the second method (fetching all the option values) would be better only if you have limited small amount of data and are very sure there will always be less data in future. But, since nobody can be so certain about the future, it is advisable to use the AJAX method always.

                      這篇關于根據(jù)另一個下拉列表填充下拉列表的最佳和最簡單的方法是什么的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                      【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!
                4. 相關文檔推薦

                  Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                  PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標不起作用)
                  PHP PDO ODBC connection(PHP PDO ODBC 連接)
                  Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術方法)
                  php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                  MSSQL PDO could not find driver(MSSQL PDO 找不到驅(qū)動程序)
                  <i id='9eekC'><tr id='9eekC'><dt id='9eekC'><q id='9eekC'><span id='9eekC'><b id='9eekC'><form id='9eekC'><ins id='9eekC'></ins><ul id='9eekC'></ul><sub id='9eekC'></sub></form><legend id='9eekC'></legend><bdo id='9eekC'><pre id='9eekC'><center id='9eekC'></center></pre></bdo></b><th id='9eekC'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='9eekC'><tfoot id='9eekC'></tfoot><dl id='9eekC'><fieldset id='9eekC'></fieldset></dl></div>
                    <tbody id='9eekC'></tbody>
                  <tfoot id='9eekC'></tfoot>

                  • <bdo id='9eekC'></bdo><ul id='9eekC'></ul>

                          • <legend id='9eekC'><style id='9eekC'><dir id='9eekC'><q id='9eekC'></q></dir></style></legend>

                            <small id='9eekC'></small><noframes id='9eekC'>

                            主站蜘蛛池模板: 91亚洲精选 | 国产剧情一区二区三区 | 欧美黄色一区 | 亚洲精品一区二区 | 一本色道精品久久一区二区三区 | 亚洲欧美第一视频 | 国产免费视频 | 日韩视频在线免费观看 | 天天想天天干 | 色综合桃花网 | 三级免费av| 日韩欧美在线观看 | 久热m3u8 | 欧美在线视频a | 国产精品日韩 | 久久99久久久久 | 国产一区二区三区精品久久久 | 国产欧美精品一区二区 | 久久久精品网站 | 97精品国产97久久久久久免费 | 国产精品无码永久免费888 | 天堂久久一区 | 黄色免费观看网站 | 久久男人| 免费黄色的视频 | 在线观看欧美日韩视频 | 小早川怜子xxxxaⅴ在线 | 999久久久 | 手机在线一区二区三区 | 久久精品免费 | 不卡在线视频 | 久久精品国产免费一区二区三区 | www精品美女久久久tv | 国产成人高清视频 | 精品区一区二区 | 蜜臀久久99精品久久久久久宅男 | 国产欧美一区二区三区免费 | 在线视频一区二区三区 | 成人久久久 | 天天操天天天 | 日日夜夜影院 |