<!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
最新推荐文章于 2023-02-21 12:01:09 发布