简体   繁体   中英

Button.Click event is not firing up

I am new in JQ. I have created this fiddle here: http://jsfiddle.net/SZ6mY/7/

All I want to do is to show an "ALERT" message when "C" button is clicked. Also I want to know that if you click "7" how you grab the value 7 in a variable in JQ?

Any input is appreciated! Thanks.

change btnClear to #btnClear . The # tells jquery that the following string is an ID and not a class, selector, etc.

$("#btnClear").click(function() {
    alert("test");
});

You comment question:

$('input:button').click(function () {
   alert(parseInt($(this).val(), 10))   
})

this code will look for ALL input buttons and bind this event to them.

您需要添加“#”以指定您要使用ID“ btnClear”。

You need a number sign to select by id, like $("#btnClear") . As for your second questions, all your numbered buttons are calling a function right now like NumPressed(7); So you can just use the parameter passed to that function. If you want to clean up your code though and remove those onclicks. You can also detect the value of the button like $(selector).val();

you should change the

$("btnClear").click(function() {
    alert("test");
});

to

$("#btnClear").click(function() {
    alert("test");
});

Then the jQuery can find the input element with id 'btnClear'.

Is that clear?

The number input elements you placed a function named NumPressed with the click event, so you can do it like normal js.

Okay! I did something like this: http://jsfiddle.net/SZ6mY/8/

So I'm assuming that in my seven variable the value 7 will be stored. Is this correct?

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM