简体   繁体   English

Button.Click事件未触发

[英]Button.Click event is not firing up

I am new in JQ. 我是JQ新手。 I have created this fiddle here: http://jsfiddle.net/SZ6mY/7/ 我在这里创建了这个小提琴: http : //jsfiddle.net/SZ6mY/7/

All I want to do is to show an "ALERT" message when "C" button is clicked. 我要做的就是单击“ C”按钮时显示一条“ ALERT”消息。 Also I want to know that if you click "7" how you grab the value 7 in a variable in JQ? 我也想知道,如果单击“ 7”,如何在JQ的变量中获取值7?

Any input is appreciated! 任何输入表示赞赏! Thanks. 谢谢。

change btnClear to #btnClear . btnClear更改为#btnClear The # tells jquery that the following string is an ID and not a class, selector, etc. #告诉jquery以下字符串是ID,而不是类,选择器等。

$("#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") . 您需要一个数字符号来按ID选择,例如$("#btnClear") As for your second questions, all your numbered buttons are calling a function right now like NumPressed(7); 至于第二个问题,所有编号的按钮现在都在调用一个函数,例如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. 如果您想清理代码并删除这些onclicks。 You can also detect the value of the button like $(selector).val(); 您还可以像$(selector).val();一样检测按钮的值$(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'. 然后,jQuery可以找到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. 数字输入元素中,您在click事件中放置了一个名为NumPressed的函数,因此您可以像普通js一样进行操作。

Okay! 好的! I did something like this: http://jsfiddle.net/SZ6mY/8/ 我做了这样的事情: http : //jsfiddle.net/SZ6mY/8/

So I'm assuming that in my seven variable the value 7 will be stored. 因此,我假设在我的七个变量中将存储值7。 Is this correct? 这个对吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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