簡體   English   中英

幫助 jQuery select 菜單樣式

[英]Help with jQuery select menu styling

I'm trying to use the jQuery UI to style my HTML select menu but I'm having a little trouble getting it working... I'm still relatively new to using jQuery so the answer to this may be fairly simple.

我的完整代碼段(使用 jQuery v1.6.2):

<link rel="stylesheet" type="text/css" href="css/ui-darkness/jquery.css">
<label for="favorite">Select favorite team</label>

    <script type="text/javascript" src="js/jquery.js"></script>
    <script type="text/javascript" src="js/jqueryui.js"></script>
    <script type="text/javascript" src="js/selectmenu.js"></script></script>
    <script type="text/javascript">$(function() {
            $('select[name=favorite]').selectmenu();
        });
    </script>

    <select name='favorite'>
        <?php

            while ($temp = mysql_fetch_assoc($query)) {
                echo "<option value=" . $temp['id'] . ">" . htmlspecialchars($temp['teamname']) . "</option>";
            }
        ?>
    </select>

但它似乎沒有做任何事情。 我的 select 菜單顯示為正常的、無聊的 HTML select 菜單。 我真的不確定我正在做的事情是完全遲鈍還是什么,但如果你知道如何讓它正常工作,請告訴我。

編輯控制台給出錯誤Uncaught TypeError: Object [object Object] has no method 'selectmenu'

$('select[name=favorite]').selectmenu();

您必須設置要使用的元素的名稱。 在這種情況下,一個名為 favourite 的 select 盒子。

您還必須將代碼放在 jQuery 的文檔中准備好 function

$(document).ready(function() {
   $('select[name=favorite]').selectmenu();
});

或使用速記

$(function() {
   $('select[name=favorite]').selectmenu();
});

為什么不嘗試給 select 提供一個 id 或 class。 然后您可以使用它的 id 或 class 從 jquery 調用它。 我不知道它是否有效,但值得一試。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM