jQuery的one()方法用法实例
2018-10-12 14:02
627 查看
本文实例讲述了jQuery的one()方法用法。分享给大家供大家参考。具体分析如下:
为匹配元素的特定事件绑定一个一次性的事件处理方法。
在语法上one()方法和bind()方法是一样的,它们的不同在于绑定的处理方法的执行次数。
语法结构:
$(selector).one(event,data,function)
参数列表:
参数 | 描述 |
type | 定义绑定到匹配元素中的事件类型。 如果有多个事件使用空格分隔。 |
data | 可选。传递给事件对象的额外数据对象。 |
function | 定义当事件发生时运行的方法。 |
实例代码:
<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="//www.jb51.net/" />
<title>one()函数-脚本之家</title>
<style type="text/css">
div{
width:100px;
height:100px;
border:1px solid red
}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("div").one("click",function(){
$(this).append("添加的内容");
})
})
</script>
</head>
<body>
<div></div>
</body>
</html>
点击div之后,可以为div添加指定的内容,但是此事件处理函数只会被执行一次。
希望本文所述对大家的jQuery程序设计有所帮助。
您可能感兴趣的文章:
相关文章推荐
- jQuery的one()方法用法实例
- jquery中one()方法的用法实例
- jquery中one()方法的用法实例
- jQuery中replaceWith()方法用法实例
- jQuery中on()方法用法实例详解
- jQuery中siblings()方法用法实例
- jQuery中append()方法用法实例
- jQuery中appendTo()方法用法实例
- jQuery中clearQueue()方法用法实例
- jQuery中unwrap()方法用法实例
- jQuery中prop()方法用法实例
- jQuery中prependTo()方法用法实例
- jQuery中filter()方法用法实例
- jQuery中next()方法用法实例
- jQuery的css()方法用法实例
- jQuery中scrollTop()方法用法实例
- jQuery中andSelf()方法用法实例
- jQuery中remove()方法用法实例
- jQuery中each()方法用法实例