ive 以下按钮
<button class="image1-button" data-image="bg_images/1.jpg">button 1</button>
<button class="image1-button" data-image="bg_images/2.jpg">button 2</button>
<button class="image1-button" data-image="bg_images/3.jpg">button 3</button>
<button class="image1-button" data-image="bg_images/4.jpg">button 4</button>
使用以下代码
$(".image1-button").click(function() {
var url = 'url(' + $(this).data('image') + ')';
$('#div1').css('background-image', url).fadeIn(500);
// what to write in this if that it works...
if('data-image="bg_images/2.jpg"') {
here should something happen if button 2 is pressed
}
我如何编写它进入并触发我的事件的 if 条件?谢谢你!