【问题标题】:How to setup default icons in button using jQuery如何使用jQuery在按钮中设置默认图标
【发布时间】:2023-03-25 01:20:01
【问题描述】:

我在 jsp 中使用 jQuery 1.8.2、jQuery ui 1.9.1、Firefox 16.0.1,我试图获得一个按钮来显示一个图标。我尝试的是:

$('button').button({ icons: {primary: "ui-icon-triangle-1-s" } });

在 div 中:

<div id="buttonDiv" style="text-align: center;"> <button class="btn-primary"  type="button" id="confirmationButton" value="confirm">Confirmation</button> </div>

然后我尝试使用 id、类、将类型设置为按钮等...,但由于某种原因它没有显示。

我知道,如果我试图将按钮设为输入按钮,那么设计和使用时将无法正常工作

$('button').button() 等.. 作为选择器,它工作正常。

这是我的 cdn 声明:

<!-- Reference the theme's stylesheet on the Google CDN -->
    <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/themes/ui-lightness/jquery-ui.css" rel="stylesheet" type="text/css"/>

    <!-- Reference jQuery and jQuery UI from the CDN. Remember that the order of these two elements is important -->
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" type="text/javascript"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js" type="text/javascript"></script>

我在这里错过了什么?

【问题讨论】:

    标签: jquery jquery-ui jsp button icons


    【解决方案1】:

    您确定没有遗漏任何其他资源吗?您是否包含了所需的 CSS 和图片?

    特别是 jquery-ui.css : http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.csshttp://code.jquery.com/ui/1.9.1/themes/base/images/ui-icons_222222_256x240.png

    编辑:

    使用您的脚本标签,我很快就写了下来,它可以工作。

    <!doctype html>
        <html>
        <head>
            <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/themes/ui-lightness/jquery-ui.css" rel="stylesheet" type="text/css"/>
            <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" type="text/javascript"></script>
            <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js" type="text/javascript"></script>
            <script type="text/javascript">
            $(document).ready(function(){
                $('button').button({ icons: {primary: "ui-icon-triangle-1-s" } });
            });
            </script>
            </head>
        <body>
            <div id="buttonDiv" style="text-align: center;"> <button class="btn-primary"  type="button" id="confirmationButton" value="confirm">Confirmation</button> </div>
        </body>
        </html>
    

    【讨论】:

    • 我错过了对图标本身的引用。所以如果我选择一个主题,我还必须引用图标?
    • 我编辑了我的原始答案。来自谷歌的远程 jquery-ui.css 使用图像的相对路径,我猜这些路径使用 ajax.googlepais.com... 作为它们的绝对路径扩展。
    • 我做的一切都是正确的,但我现在看到了,我在按钮语句周围省略了我的函数。我忽略了在这里检查显而易见的事情。谢谢!
    猜你喜欢
    • 2021-07-11
    • 1970-01-01
    • 1970-01-01
    • 2012-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 2019-06-01
    相关资源
    最近更新 更多