开发者

JQuery onclick doing nothing

开发者 https://www.devze.com 2023-01-30 09:10 出处:网络
So here is my button: <div id=\"calculateButton\" style=\"cursor: pointer;\"> <img src=\"<%= VirtualPathUtility.ToAbsolute(\"~/img/chic/btn_calculate.gif\")%>\" />

So here is my button:

<div id="calculateButton" style="cursor: pointer;">
    <img src="<%= VirtualPathUtility.ToAbsolute("~/img/chic/btn_calculate.gif")%>" />
</div>

And here is the javascript:

$('#calculateButton').click(function () {
    alert('Calculating...');
});

When I click the button nothing happens. What am I doing wrong?

Edits:

$(document).ready(function () {

        $("#prepaymentTable").bubble({ width: 400, title: 'Prepayment' });
        $("#exposureTable").bubble({ width: 400, title: 'Exposure' });

        $('#calculateButton').click(function () {
            alert('Calculating...');
        });

    });
开发者_如何学Python

The bubble plugins both work...but not the button click...


Make sure you're attaching the click handler inside a document.ready handler, after the element has loaded, like this:

$(function() {
  $('#calculateButton').click(function () {
    alert('Calculating...');
  });
});

If it's created later as the result of AJAX, etc, use .live(), for example:

$('#calculateButton').live('click', function () {
0

精彩评论

暂无评论...
验证码 换一张
取 消