为了账号安全,请及时绑定邮箱和手机立即绑定

好奇怪啊,

$("body").on("click","#btntest", function () {

    $(this).attr("disabled", "true");

})

里面的$(this),按理解应该指的是“body”啊,可是为什么又指到[data]上去了呢?

正在回答

2 回答

学习了,thank u for sharing~

0 回复 有任何疑惑可以回复我~

好了看看真实的on的调用方法吧:(从1.7版本开始)

.on( events, [selector,][data,] function )

events

Type: String

One or more space-separated event types and optional namespaces, such as "click" or "keydown.myPlugin".

selector

Type: String

A selector string to filter the descendants of the selected elements that trigger the event. If the selector is null or omitted, the event is always triggered when it reaches the selected element.

data

Type: Anything

Data to be passed to the handler in event.data when an event is triggered.

handler

Type: Function( Event eventObject )

A function to execute when the event is triggered. The value false is also allowed as a shorthand for a function that simply does return false.


或者是:

.on( events [, selector ] [, data ] )

events

Type: PlainObject

An object in which the string keys represent one or more space-separated event types and optional namespaces, and the values represent a handler function to be called for the event(s).

selector

Type: String

A selector string to filter the descendants of the selected elements that will call the handler. If the selector is null or omitted, the handler is always called when it reaches the selected element.

data

Type: Anything

Data to be passed to the handler in event.data when an event occurs.



0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
jQuery基础课程
  • 参与学习       154768    人
  • 解答问题       7184    个

加入课程学习,有效提高前端开发速度

进入课程
意见反馈 帮助中心 APP下载
官方微信