简体   繁体   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. 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.

My full code segment (using jQuery v1.6.2):我的完整代码段(使用 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>

But it doesn't seem to do anything.但它似乎没有做任何事情。 My select menu appears as a normal, boring HTML select menu.我的 select 菜单显示为正常的、无聊的 HTML select 菜单。 I'm really not sure at all if what I'm doing is completely retarded or what, but let me know if you know how to get this working properly.我真的不确定我正在做的事情是完全迟钝还是什么,但如果你知道如何让它正常工作,请告诉我。

EDIT Console gives error Uncaught TypeError: Object [object Object] has no method 'selectmenu'编辑控制台给出错误Uncaught TypeError: Object [object Object] has no method 'selectmenu'

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

You must set the name of the element you want to use.您必须设置要使用的元素的名称。 In this case, a select box with the name favorite.在这种情况下,一个名为 favourite 的 select 盒子。

You must also place the code within jQuery's document ready function您还必须将代码放在 jQuery 的文档中准备好 function

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

or use the shorthand或使用速记

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

why don't you try to give an id or class to the select.为什么不尝试给 select 提供一个 id 或 class。 then you can call it from jquery by using it id or class.然后您可以使用它的 id 或 class 从 jquery 调用它。 i don't know it will work or not, but worth it a try.我不知道它是否有效,但值得一试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM