I having difficulty in meeting add an event click on a div tag with runat = "server". This works perfectly on IE but not on chrome, mozilla .. Search error :-)
Here is the code I tried
JAVASCRIPT:
function showAlertAnomalie() {
alert("Handler test");
}
ASP:
<div id="btn_alert_anomalie" class="alertAnomalieClass" runat="server" onclick="showAlertAnomalie" >
<asp:Label runat="server" Text="Alert annomaly" Font-Bold="true" Font-Size="12" ForeColor="White" style="cursor:pointer;"></asp:Label>
</div>
I ave also try this but not work.. :
$("#btn_alert_anomalie").click(function () {
alert("Handler test");
});
try with class
of div
as
$(".alertAnomalieClass").click(function () {
alert("Handler test");
});
here is FIDDLE
An inline onclick
attribute is supposed to contain the body of the click handler, not the name of it. Try this:
onclick="showAlertAnomalie();"
Here is a demonstration: http://jsfiddle.net/UgcEQ/
The problem was that doing this:
onclick="showAlertAnomalie"
is equivalent to doing this:
var btn = document.getElementById('btn_alert_anomalie');
btn.onclick = function(){
showAlertAnomalie
}
which doesn't really do anything.
Try :
$('#<%=btn_alert_anomalie.ClientID%>').click(function () {
alert("Handler test");
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.