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 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧