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++;
    }
    
    打赏 评论

相关推荐 更多相似问题