javascript Jquery点击提醒()

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13008603/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 17:36:57  来源:igfitidea点击:

Jquery click alert()

javascriptjquery

提问by Rafa? Developer

Do you know why this method click doesn't show alert? Because I'm not able to catch this event.

你知道为什么这个方法点击不显示警报吗?因为我无法赶上这个事件。

<!DOCTYPE html>
<html>
<head>
<script src="jquery.js"></script>
<script>
jQuery(function () {
    jQuery(".jtable-command-button.jtable-edit-command-button").click(function () {
        alert("asdas");
    });
});

</script>
</head>
<body>

<h1>My First JavaScript</h1>
<p id="demo">This is a paragraph.</p>

<button class="jtable-command-button jtable-edit-command-button" title="Edytuj pozycj?">

</body>
</html> 

I give you for all of you points for help [closed] thanks

我给你所有的帮助点[关闭]谢谢

回答by Quentin

  1. You are trying to use a $function (probably from jQuery) without defining it (e.g. by loading jQuery)
  2. You are trying to find the event handler before the element you are binding to has been created
  3. You are using an idselector but the element doesn't have an id (it does have a class) (Note: after the first edit of the question, this is no longer the case)
  4. You are using a descendant combinatorand a type selector, but the typeshould be a classand the element you are targeting belongs to both classes. It doesn't have an ancestor element which is a member of either of the classes. (Note: The HTML class attribute takes a space separated listof classes)
  5. The end tag and label for the button are missing
  1. 您正在尝试使用一个$函数(可能来自 jQuery)而不定义它(例如通过加载 jQuery)
  2. 您正在尝试在创建要绑定到的元素之前找到事件处理程序
  3. 您正在使用id选择器,但该元素没有 id(它确实有一个类)(注意:在第一次编辑问题后,情况不再如此
  4. 您正在使用 adescendant combinator和 a type selector,但type应该是 aclass并且您定位的元素属于这两个类。它没有属于任一类的祖先元素。(注意:HTML 类属性采用空格分隔的类列表
  5. 按钮的结束标记和标签丢失

A fixed version of the JS part would be:

JS 部分的固定版本是:

<script src="jquery.js"></script> <!-- Set this path correctly -->
<script>
jQuery(function () {
    jQuery(".jtable-command-button.jtable-edit-command-button").click(function () {
        alert("asdas");
    });
});
</script>

回答by Cecil Theodore

$(".jtable-command-button.jtable-edit-command-button").click(function () {
alert("asdas");

You need to include the '.' after .jtable-command-buttonas jtable-edit-command-buttonis a class.

您需要..jtable-command-button原样后包含“ ” jtable-edit-command-button

回答by Yograj Gupta

You have class name, so class selecter starts with .in jquery.

您有类名,因此类选择器以.jquery开头。

$(".jtable-command-button.jtable-edit-command-button").click(function () {
    alert("asdas");
});

回答by rajesh kakawat

you should use . for class and # for id

你应该使用 . 用于类和 # 用于 id

$(".jtable-command-button").click(function () {
   alert("asdas");
});

回答by LorDex

I hope you have jQuery declared? If so, try this:

我希望你有 jQuery 声明?如果是这样,试试这个:

$(".jtable-command-button.jtable-edit-command-button").click(function () {
   alert("asdas");
}

回答by Hkachhia

As per your code you have used # for call click event function But # is use for ID and dot (.) is used for class so you have used .(dot) instead of #

根据您的代码,您已将 # 用于调用单击事件函数,但 # 用于 ID,而点 (.) 用于类,因此您使用了 .(dot) 而不是 #

 $(".jtable-command-button.jtable-edit-command-button").click(function () {
    alert("asdas");
});

回答by Franky

Assuming you've downloaded jquery you have to import the js file:

假设您已下载 jquery,则必须导入 js 文件:

<script type="text/javascript" src="yourPath/jquery-1.7.2.js"></script>  //your jquery version

Then you can try as above answers or:

然后你可以试试上面的答案或者:

$("button[title='Edytuj pozycj?']").click(function(){
alert("asdad");
});