2014-07-08 56 views
0

我正在尝试使我的移动网络应用显得更具响应能力。所以,当你点击一个图像的图标,我想使用jQuery的手机,而它被点击显示不同的图像(不同的颜色),使它看起来有些事情已经完成,然后当你放手它应该改回来。按钮点击伪造

我在尝试以下,但它似乎并没有被解雇。任何人有任何提示?

$(document).ready(function() { 

    $('.homeAlerts').on("vmousedown", "a", function() { 
     console.log("Clicked"); 
     $('#homeAlerts').attr('src','mages/HomeIcons/typeOneClicked_0003_Alerts'); 

    }); 


    $('.homeAlerts').on("vmouseup", "a", function() { 
     $('#homeAlerts').attr('src','mages/HomeIcons/typeOne_0003_Alerts.png'); 
    }); 

}); 

标记

<div class="iconL"> 
         <a href="#alerts" class="homeAlerts"> 
          <img id="homeAlerts" src="images/HomeIcons/typeOne_0003_Alerts.png" /> 
          <center class="pullup">Alerts</center> 
         </a> 
        </div> 
+1

'$(“a.homeAlerts”)。on(........)'。编辑:不要在jQM中使用'.ready()',使用[page events](http://jqmtricks.wordpress.com/2014/03/26/jquery-mobile-page-events/)。 – Omar

+0

在您发布的HTML标记中的任何'.homeAlerts'元素内没有锚标签 –

+0

homeAlerts是锚标签,但? – TMB87

回答

1

使用jQuery的鼠标按下和mouseup函数来代替:

$("img#homeAlerts").mousedown(function(){ 
     $(this).attr("src", "images/HomeIcons/typeOneClicked_0003_Alerts.png") 
}); 
$("img#homeAlerts").mouseup(function(){ 
     $(this).attr("src", "images/HomeIcons/typeOne_0003_Alerts.png") 
}); 
-1

回答你原来的问题,肯定你应该做的:

$('#homeAlerts').on("vmousedown", "a", function() { 
    console.log("Clicked"); 
    $(this).attr('src','mages/HomeIcons/typeOneClicked_0003_Alerts'); 

}); 


$('#homeAlerts').on("vmouseup", "a", function() { 
    $(this).attr('src','mages/HomeIcons/typeOne_0003_Alerts.png'); 
}); 

(你的选举人试图选择一个班级,但你的图像上有一个ID)