0

Currently I have a button

<input id="fireAction" type="button" class="submit" onclick="disableSubmit('preFlight');"><br>

Then I change the background image of the button in different case

eg.

#('#fireAction').css('background-image','url(fail.jpg)');
#('#fireAction').css('background-image','url(success.jpg)');

However, since the size of fail.jpg / success.jpg is not the same, how to define some css (Tried width:auto but not working) to make the button fit the size according to the size of background image? thanks

4

1 回答 1

3

我不知道您是在寻找 JS、jQuery 还是 CSS 答案,但就 CSS 而言,您无法根据 调整元素大小background-image,您可以做的是,您可以input type=image在此处使用

<input type="image" src="#" alt="Image" />

或者,如果您想坚持使用 JavaScript 或 jQuery,则声明 2 个具有自定义宽度的类并根据您的要求切换它们

于 2013-06-24T07:01:52.760 回答