douou9786 2013-05-16 03:05
浏览 113
已采纳

一个while循环中的jQuery下拉列表

I want to use the jQuery Dropdown CheckList in a while loop. But in only display the jQuery Dropdown Checklist in the first row. For the rest of the row it didn't call the jQuery Dropdown Checklist function. Is there any way for me to call the jQuery function dynamically.

//This is the java script for calling the dropdown list
    <meta http-equiv="refresh" content="600" >
        <!-- Apply dropdown check list to the selected items  -->
    <script type="text/javascript">

    $(document).ready(function(){$("#s1").dropdownchecklist( { width: 300 } );});

     </script>  
//this is the while loop which display the list of row with drop down checklist in it
         //display the list of rows



 while($rows = mysql_fetch_array($query)){

        <select id="s1" multiple="multiple" >

        <option value=""></option>
    <?php while($rowsakh= mysql_fetch_array($resultakh)) { ?>
    <option  value='<?php echo $rowsakh['diet_id']; ?>'><?php echo $rowsakh['diet_name']; ?></option> <?php } ?>
    </select>
         }//end while loop

If I try to make the id="s1" to be a dynamic variable where it increases for each loop. Is there any way to make the id="s1" dynamically or the syntax for me to do it.

  • 写回答

1条回答 默认 最新

  • drn34916 2013-05-16 03:30
    关注

    If you want the id to be dynamic like id="s1" id="s2" you can accomplish this by defining a variable to the value of 1 and the increase the variable by 1 for every time it looks so your code would be like this,

    $i = 1;
    while($rows = mysql_fetch_array($query)){
    
    <select id="s<?php echo $i; ?>" multiple="multiple" >
        <option value=""></option>
        <?php while($rowsakh= mysql_fetch_array($resultakh)) { ?>
        <option  value='<?php echo $rowsakh['diet_id']; ?>'><?php echo $rowsakh['diet_name']; ?></option> <?php } ?>
    </select>
    $i++;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 chaquopy python 安卓
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题