简体   繁体   English

jQuery UI动态图标

[英]jquery ui dynamic icon

I have a set of buttons and Im trying to instead of setting individual icons for them, use an attribute and one-for-all function to set their icon. 我有一组按钮,我试图代替为它们设置单个图标,而是使用属性和所有人功能来设置其图标。 Here is an example of my button : 这是我的按钮的示例:

<button title="New Project" id="New" class="Nx button" type="document"></button>

and here is sort of what I want to achieve : 这是我想要实现的目标:

$('.button').button({
   icons: { primary:'ui-icon-'+$(this).attr("type") },
   text:false
});

but it doesnt work. 但它不起作用。 so pretty much I want to have an internal reference to the element's "type" attribute to be able to set the icon 因此,我几乎希望对元素的“ type”属性进行内部引用,以便能够设置图标

Here is a demo of how I would go about it. 这是我将如何处理的演示。 I have also provided the code below. 我还提供了下面的代码。 Let me know if you need anything else. 需要帮助请叫我。

CODE: 码:

$(document).ready(function(){
    $("button").each(function(index,element){
       $(element).button({
            icons: {
                primary: "ui-icon-" + $(this).attr('type')
            },
                text:false
            })
    });
});

DEMO: http://jsfiddle.net/sZdd8/11/ 演示: http : //jsfiddle.net/sZdd8/11/

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

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