douyi7055 2013-04-16 21:32
浏览 37

Jquery插件无法正常工作

I am very new to jQuery. I am trying to use a plugin called Searchable Dropdown, that I got from here: http://jsearchdropdown.sourceforge.net/ . but I cannot figure out how to make it work.. What am I doing wrong?

<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script>
<script src="scripts/jquery.searchabledropdown-1.0.8.min.js" type="text/javascript"></script>
<script>

    $(document).ready(function() {
        $("select").searchable();
    });
</script>

</head>

<?php
echo "<form method='post' action='' id='employeesselection'>
  <select    name='select_employee' id='select_employee'>";
       while($row=mysql_fetch_array($employees)){
            $selected = ($row['Id'] == $_POST['select_employee'])?'selected="selected"':'';
    echo '<option '.$selected.' value="'.$row['Id'].'">'.$row['Etunimi'].' - '. $row['Sukunimi'].'</option>';

}
   echo "</select></form>";

The select is working fine but searching in the select as the jQuery should enable, is not working.

  • 写回答

2条回答 默认 最新

  • dongrenshi0889 2013-04-17 12:34
    关注

    Try also to give your code some semantic:

    <?php 
    
    // DATABASE CONNECTION
    // DATABASE QUERY
    
     ?>
    <html lang="en">
    <head>
    
    <!-- CSS -->
    
    </head>
    
    <body>
        <form action="" method="post" id="employeesselection">
            <select name="select_employee" id="select_employee">
                <?php while ( $row = mysql_fetch_array( $employees ) ) {
                    $selected = ( $row['id'] == $_POST['select_employee'] ) ? ' selected ' : '';
                ?>      
                    <option <?php echo $selected ?> value="<?php echo $row['id'] ?>">
                        <?php echo $row['etunimi'] ?> - <?php echo $row['sukunimi'] ?>
                    </option>
                <?php } ?>
            </select>
        </form>
    
    <!-- All Javascript down here -->
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script>
    <script src="scripts/jquery.searchabledropdown-1.0.8.min.js" type="text/javascript"></script>
    
    <script>
        $(document).ready(function() {
                $("select").searchable();
        });
    </script>
    </body>
    </html>
    

    Maybe the error isn't in your javascript but in php...

    Good luck debugging!

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度