<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery $(selector).trigger() 触发事件</title>
<style>
*{
margin:0;
padding:0;
font: 20px/1.5 KaiTi,'Microsoft yahei'
}
</style>
<script src="https://www.w3school.com.cn/jquery/jquery.js"></script>
<script>
/*参考:
https://www.runoob.com/jquery/event-trigger.html
https://www.w3school.com.cn/jquery/event_trigger.asp
* 知识点:
* 1.$(selector).trigger(event,[param1,param2,...])
* event,必需。规定指定元素要触发的事件。
可以使自定义事件(使用 bind() 函数来附加),或者任何标准事件。
[param1,param2,...],可选。传递到事件处理程序的额外参数。
额外的参数对自定义事件特别有用。
2.$(selector).trigger(eventObj)
* eventObj,必需。规定事件发生时运行的函数。*/
$(function () {
// 绑定事件。
$("input").select(function () {
$("input").after("文本被选中!");
});
$("button").click(function () {
// 触发事件。
// $("input").trigger("select");
$("input").select();
});
});
</script>
</head>
<body>
<label for="FirstName">FirstName</label>: <input type="text" id="FirstName" name="FirstName" value="Hello World"/>
<br/>
<button>激活 input 域的 select 事件</button>
</body>
</html>
最后
以上就是高贵音响最近收集整理的关于jQuery $(selector).trigger() 触发事件.html的全部内容,更多相关jQuery内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复