doctype html> on demo p { background: yellow; font-weight: bold; cursor: pointer; padding: 5px; } p.over { background: #ccc; } span { color: red; } Click me! c 1 c 2
initial-scale=1.0">JQuery 事件绑定Item1Item2Item3// 使用事件代理绑定列表项点击事件$('#myList').on('click','li',function(){alert('列表项被点击了!');});// 动态添加一个列表项$('#myList').append('Item 4'); 在这个例子中,我们使用了事件代理,将点击事件绑定到了...
$("div").on("mouseenter mouseleave", function() { $(this).toggleClass("current"); }); // (2) on可以实现事件委托(委派) // $("ul li").click(); $("ul").on("click", "li", function() { alert(11); }); // click 是绑定在ul 身上的,但是 触发的对象是 ul 里面的小li // ...
Type:Function(EventeventObject [,AnythingextraParameter ] [, ... ] ) A function to execute when the event is triggered. The valuefalseis also allowed as a shorthand for a function that simply doesreturn false. version added:1.7.on( events [, selector ] [, data ] ) ...
$("#button-container button").on("click",function(event){ hiddenBox.show(); }); Ajax Call a local script on the server/api/getWeatherwith the query parameterzipcode=97201and replace the element#weather-temp's html with the returned text. ...
To add a property name to this list, use jQuery.event.props.push( "newPropertyName" ). However, be aware that every event processed by jQuery will now attempt to copy this property name from the native browser event to jQuery's constructed event. If the property does not exist for that...
$(selector).on(event,childSelector,data,function) 参数描述 event必需。规定要从被选元素添加的一个或多个事件或命名空间。 由空格分隔多个事件值,也可以是数组。必须是有效的事件。 childSelector可选。规定只能添加到指定的子元素上的事件处理程序(且不是选择器本身,比如已废弃的 delegate() 方法)。
.on( events [, selector ] [, data ], handler(eventObject) ) 数据录入 $("#shortcutUl").on("click", ".shortcut", function (e) { console.log($(e.target)); }) click“数据录入”, console是会输出oboject{h5}的,即.on()的...
click event Bind an event handler to the “click” event, or trigger that event on an element. Also in:Deprecated>Deprecated 3.3|Events>Mouse Events .click() Bind an event handler to the “click” event, or trigger that event on an element. ...
data:当一个事件被触发时要传递event.data给事件处理函数。 fn:该事件被触发时执行的函数。 false 值也可以做一个函数的简写,返回false。 替换bind() 当第二个参数'selector'为null时,on()和bind()其实在用法上基本上没有任何区别了,所以我们可以认为on()只是比bind()多了一个可选的'selector'参数,所以on...