0

今天我刚刚从http://jqueryui.com/download下载了一个自定义的 Jquery UI 存档,我解压了它。但是,当我打开存档的 index.html 文件时,我发现此页面上的按钮示例不起作用。该按钮像往常一样呈现,没有任何 UI 样式,此页面中的所有元素的其余部分工作正常。它是来自 JqueryUI 网站下载的错误吗?还是我忘记了什么?!

以下是 index.html 的代码。

     <!DOCTYPE html>
        <html>
            <head>
                <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
                <title>jQuery UI Example Page</title>
                <link type="text/css" href="css/ui-lightness/jquery-ui-1.8.22.custom.css" rel="stylesheet" />
                <script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
                <script type="text/javascript" src="js/jquery-ui-1.8.22.custom.min.js"></script>
                <script type="text/javascript">
                    $(function(){

                        // Accordion
                        $("#accordion").accordion({ header: "h3" });

                        // Tabs
                        $('#tabs').tabs();

                        // Dialog
                        $('#dialog').dialog({
                            autoOpen: false,
                            width: 600,
                            buttons: {
                                "Ok": function() {
                                    $(this).dialog("close");
                                },
                                "Cancel": function() {
                                    $(this).dialog("close");
                                }
                            }
                        });

                        // Dialog Link
                        $('#dialog_link').click(function(){
                            $('#dialog').dialog('open');
                            return false;
                        });

                        // Datepicker
                        $('#datepicker').datepicker({
                            inline: true
                        });

                        // Slider
                        $('#slider').slider({
                            range: true,
                            values: [17, 67]
                        });

                        // Progressbar
                        $("#progressbar").progressbar({
                            value: 20
                        });

                        //hover states on the static widgets
                        $('#dialog_link, ul#icons li').hover(
                            function() { $(this).addClass('ui-state-hover'); },
                            function() { $(this).removeClass('ui-state-hover'); }
                        );

                    });
                </script>
                <style type="text/css">
                    /*demo page css*/
                    body{ font: 62.5% "Trebuchet MS", sans-serif; margin: 50px;}
                    .demoHeaders { margin-top: 2em; }
                    #dialog_link {padding: .4em 1em .4em 20px;text-decoration: none;position: relative;}
                    #dialog_link span.ui-icon {margin: 0 5px 0 0;position: absolute;left: .2em;top: 50%;margin-top: -8px;}
                    ul#icons {margin: 0; padding: 0;}
                    ul#icons li {margin: 2px; position: relative; padding: 4px 0; cursor: pointer; float: left;  list-style: none;}
                    ul#icons span.ui-icon {float: left; margin: 0 4px;}
                </style>
            </head>
            <body>
            <h1>Welcome to jQuery UI!</h1>
            <p style="font-size: 1.3em; line-height: 1.5; margin: 1em 0; width: 50%;">This page demonstrates the widgets you downloaded using the theme you selected in the download builder. We've included and linked to minified versions of <a href="js/jquery-1.7.2.min.js">jQuery</a>, your personalized copy of <a href="js/jquery-ui-1.8.22.custom.min.js">jQuery UI (js/jquery-ui-1.8.22.custom.min.js)</a>, and <a href="css/ui-lightness/jquery-ui-1.8.22.custom.css">css/ui-lightness/jquery-ui-1.8.22.custom.css</a> which imports the entire jQuery UI CSS Framework. You can choose to link a subset of the CSS Framework depending on your needs. </p>
            <p style="font-size: 1.2em; line-height: 1.5; margin: 1em 0; width: 50%;">You've downloaded components and a theme that are compatible with jQuery 1.3+. Please make sure you are using jQuery 1.3+ in your production environment.</p>

            <p style="font-weight: bold; margin: 2em 0 1em; font-size: 1.3em;">YOUR COMPONENTS:</p>

                <!-- Accordion -->
                <h2 class="demoHeaders">Accordion</h2>
                <div id="accordion">
                    <div>
                        <h3><a href="#">First</a></h3>
                        <div>Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.</div>
                    </div>
                    <div>
                        <h3><a href="#">Second</a></h3>
                        <div>Phasellus mattis tincidunt nibh.</div>
                    </div>
                    <div>
                        <h3><a href="#">Third</a></h3>
                        <div>Nam dui erat, auctor a, dignissim quis.</div>
                    </div>
                </div>

                <!-- Autocomplete -->
                <h2 class="demoHeaders">Autocomplete</h2>
                <div>
                    <input id="autocomplete" style="z-index: 100; position: relative" title="type &quot;a&quot;" />
                </div>

                <!-- Button -->
                <h2 class="demoHeaders">Button</h2>
                <button id="button">A button element</button>
                <form style="margin-top: 1em;">
                    <div id="radioset">
                        <input type="radio" id="radio1" name="radio" /><label for="radio1">Choice 1</label>
                        <input type="radio" id="radio2" name="radio" checked="checked" /><label for="radio2">Choice 2</label>
                        <input type="radio" id="radio3" name="radio" /><label for="radio3">Choice 3</label>
                    </div>
                </form>


                <!-- Tabs -->
                <h2 class="demoHeaders">Tabs</h2>
                <div id="tabs">
                    <ul>
                        <li><a href="#tabs-1">First</a></li>
                        <li><a href="#tabs-2">Second</a></li>
                        <li><a href="#tabs-3">Third</a></li>
                    </ul>
                    <div id="tabs-1">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</div>
                    <div id="tabs-2">Phasellus mattis tincidunt nibh. Cras orci urna, blandit id, pretium vel, aliquet ornare, felis. Maecenas scelerisque sem non nisl. Fusce sed lorem in enim dictum bibendum.</div>
                    <div id="tabs-3">Nam dui erat, auctor a, dignissim quis, sollicitudin eu, felis. Pellentesque nisi urna, interdum eget, sagittis et, consequat vestibulum, lacus. Mauris porttitor ullamcorper augue.</div>
                </div>

                <!-- Dialog NOTE: Dialog is not generated by UI in this demo so it can be visually styled in themeroller-->
                <h2 class="demoHeaders">Dialog</h2>
                <p><a href="#" id="dialog_link" class="ui-state-default ui-corner-all"><span class="ui-icon ui-icon-newwin"></span>Open Dialog</a></p>


                <h2 class="demoHeaders">Overlay and Shadow Classes <em>(not currently used in UI widgets)</em></h2>
                <div style="position: relative; width: 96%; height: 200px; padding:1% 4%; overflow:hidden;" class="fakewindowcontain">
                    <p>Lorem ipsum dolor sit amet,  Nulla nec tortor. Donec id elit quis purus consectetur consequat. </p><p>Nam congue semper tellus. Sed erat dolor, dapibus sit amet, venenatis ornare, ultrices ut, nisi. Aliquam ante. Suspendisse scelerisque dui nec velit. Duis augue augue, gravida euismod, vulputate ac, facilisis id, sem. Morbi in orci. </p><p>Nulla purus lacus, pulvinar vel, malesuada ac, mattis nec, quam. Nam molestie scelerisque quam. Nullam feugiat cursus lacus.orem ipsum dolor sit amet, consectetur adipiscing elit. Donec libero risus, commodo vitae, pharetra mollis, posuere eu, pede. Nulla nec tortor. Donec id elit quis purus consectetur consequat. </p><p>Nam congue semper tellus. Sed erat dolor, dapibus sit amet, venenatis ornare, ultrices ut, nisi. Aliquam ante. Suspendisse scelerisque dui nec velit. Duis augue augue, gravida euismod, vulputate ac, facilisis id, sem. Morbi in orci. Nulla purus lacus, pulvinar vel, malesuada ac, mattis nec, quam. Nam molestie scelerisque quam. </p><p>Nullam feugiat cursus lacus.orem ipsum dolor sit amet, consectetur adipiscing elit. Donec libero risus, commodo vitae, pharetra mollis, posuere eu, pede. Nulla nec tortor. Donec id elit quis purus consectetur consequat. Nam congue semper tellus. Sed erat dolor, dapibus sit amet, venenatis ornare, ultrices ut, nisi. Aliquam ante. </p><p>Suspendisse scelerisque dui nec velit. Duis augue augue, gravida euismod, vulputate ac, facilisis id, sem. Morbi in orci. Nulla purus lacus, pulvinar vel, malesuada ac, mattis nec, quam. Nam molestie scelerisque quam. Nullam feugiat cursus lacus.orem ipsum dolor sit amet, consectetur adipiscing elit. Donec libero risus, commodo vitae, pharetra mollis, posuere eu, pede. Nulla nec tortor. Donec id elit quis purus consectetur consequat. Nam congue semper tellus. Sed erat dolor, dapibus sit amet, venenatis ornare, ultrices ut, nisi. </p>

                    <!-- ui-dialog -->
                    <div class="ui-overlay"><div class="ui-widget-overlay"></div><div class="ui-widget-shadow ui-corner-all" style="width: 302px; height: 152px; position: absolute; left: 50px; top: 30px;"></div></div>
                    <div style="position: absolute; width: 280px; height: 130px;left: 50px; top: 30px; padding: 10px;" class="ui-widget ui-widget-content ui-corner-all">
                        <div class="ui-dialog-content ui-widget-content" style="background: none; border: 0;">
                            <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
                        </div>
                    </div>

                </div>


                <!-- ui-dialog -->
                <div id="dialog" title="Dialog Title">
                    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
                </div>


                <h2 class="demoHeaders">Framework Icons (content color preview)</h2>
                <ul id="icons" class="ui-widget ui-helper-clearfix">

                <li class="ui-state-default ui-corner-all" title=".ui-icon-carat-1-n"><span class="ui-icon ui-icon-carat-1-n"></span></li>
.........
                .......
                <li class="ui-state-default ui-corner-all" title=".ui-icon-grip-diagonal-se"><span class="ui-icon ui-icon-grip-diagonal-se"></span></li>
                </ul>


                <!-- Slider -->
                <h2 class="demoHeaders">Slider</h2>
                <div id="slider"></div>

                <!-- Datepicker -->
                <h2 class="demoHeaders">Datepicker</h2>
                <div id="datepicker"></div>

                <!-- Progressbar -->
                <h2 class="demoHeaders">Progressbar</h2>
                <div id="progressbar"></div>

                <!-- Highlight / Error -->
                <h2 class="demoHeaders">Highlight / Error</h2>
                <div class="ui-widget">
                    <div class="ui-state-highlight ui-corner-all" style="margin-top: 20px; padding: 0 .7em;">
                        <p><span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"></span>
                        <strong>Hey!</strong> Sample ui-state-highlight style.</p>
                    </div>
                </div>
                <br/>
                <div class="ui-widget">
                    <div class="ui-state-error ui-corner-all" style="padding: 0 .7em;">
                        <p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>
                        <strong>Alert:</strong> Sample ui-state-error style.</p>
                    </div>
                </div>

            </body>
        </html>
4

1 回答 1

1

在您的 js 代码中,按钮未初始化。尝试在js中输入此代码

 $('#button').button();

在您的情况下, ID#button是对这部分 html 的调用

<button id="button">A button element</button>
于 2012-08-06T01:48:06.823 回答