jQuery click()

jQuery click() method fires on clicking an HTML element. This method will attach an event handler to the click event. We can do desired manipulations on the selected HTML element using this event handler.

jQuery click()方法在单击HTML元素时触发。 此方法会将事件处理程序附加到click事件 。 我们可以使用此事件处理程序对选定HTML元素进行所需的操作。

jQuery单击 (jQuery click)

jQuery click() event syntax:

jQuery click()事件语法:

  • click()

    click()

Here click() method is used without an argument.

在这里,click()方法使用时不带参数。

  • click(handler)

    点击(处理程序)

The handler could be any function that is executed each time the event is fired.

处理程序可以是每次触发事件时执行的任何函数。

jQuery单击示例 (jQuery Click Example)

Following example demonstrates the use of jQuery click() method.

以下示例演示了jQuery click()方法的用法。

<!DOCTYPE html>
<html>
<head>
<title>jQuery Click Event Example</title>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script> 
$(document).ready(function(){
  $(".divClass1").click(function(){
    $( this ).slideUp("slow");
  });
});
$(document).ready(function(){
  $(".divClass2").click(function(){
    $( this ).html("Mouse Clicked");
  });
});
</script>
 
<style> 
.divClass1
{
    padding:5px;
    text-align:center;
    background-color:yellow;
    border:solid 1px;
}
.divClass2
{
    padding:5px;
    text-align:center;
    background-color:grey;
    border:solid 1px;
}
</style>
</head>
<body>


<div class="divClass1">click me to slide Up</div>
<div class="divClass2">Click Me to Change Text</div>

</body>
</html>

In this example, you can see that click() method is triggered while clicking on the <div> element. In this method, we pass a handler to do the sliding transition and changing HTML text of the selected <div> element. The slideUp() method executes each time when the click event is fired.

在此示例中,您可以看到click() <div>元素时触发了click()方法。 在此方法中,我们传递一个处理程序以进行滑动过渡并更改所选<div>元素HTML文本。 每次触发click事件时,都会执行slideUp()方法。

jQuery点击演示 (jQuery click demo)

You can see above example in action by visiting below link.
jQuery Click Event Demo

您可以通过访问下面的链接查看上面的示例。
jQuery Click事件演示

翻译自: https://www.journaldev.com/4944/jquery-click

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值