Add an image to the jquery button

假如想象 提交于 2019-12-11 03:20:56

问题


I am wondering how to add an image to the jquery button. Till now I was using the jquery ui button in my project and I got custom images from the graphics team, so I would like to implement them.

submit.button({ icons: {primary:'ui-icon-trash'}, text: false })

How to add custom image to this jquery button?


回答1:


<button>Trash</button>
<style>
    .ui-button ​.ui-button-icon-primary {
        background: url('/my-custom-trash-image.png');
    }​
</style>
<script>
    $(function() {
        $('button').button({
            icons: {
                primary: 'ui-icon-trash'
            },
            text: false
        });
    });
</script>

Unfortunately you do have to pass in a valid value for the primary icon even though it won't be used.

Live Example - http://jsfiddle.net/aMVrz/




回答2:


I would just assign a class to the button...

$("#buttonId").button({

    icons: {primary: null},
    text: false

}).addClass("ButtonClass");

Then your CSS class could look something like this...

.ButtonClass
{
    background-image: url(../images/Button.png);   
    background-repeat: no-repeat; 
    border: none;    
}


来源:https://stackoverflow.com/questions/11141607/add-an-image-to-the-jquery-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!