Home  >  Article  >  Web Front-end  >  What should I do if jquery does not support on?

What should I do if jquery does not support on?

藏色散人
藏色散人Original
2021-02-02 09:09:102401browse

jquery does not support on because versions before jquery 1.7 do not support on, and starting from jQuery version 1.7, the on() method is a new replacement for the bind(), live() and delegate() methods. The solution is to update the jquery version.

What should I do if jquery does not support on?

The operating environment of this article: windows7 system, jquery3.2.1 version, Dell G3 computer.

Does jquery not support the on() method? Versions before jquery1.7 do not support on, and versions after jquery1.7 support on. As of jQuery version 1.7, the on() method is the new replacement for the bind(), live() and delegate() methods.

on() method adds one or more event handlers on the selected element and sub-elements.

Since jQuery version 1.7, the on() method is the new replacement for the bind(), live(), and delegate() methods. This method brings a lot of convenience to the API and is recommended because it simplifies the jQuery code base.

Note: Event handlers added using the on() method apply to current and future elements (such as new elements created by scripts).

Syntax

$(selector).on(event,childSelector,data,function)

Parameters:

event Required. Specifies one or more events or namespaces to be removed from the selected elements. Multiple event values ​​separated by spaces, can also be an array. Must be a valid event.

childSelector Optional. Specifies that event handlers can only be added to specified child elements (and not the selector itself, such as the deprecated delegate() method).

data Optional. Specifies additional data to be passed to the function.

function Optional. Specifies a function to run when an event occurs.

Recommendation: "jquery video tutorial"

Example:

<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  $("p").on("click",function(){
    alert("段落被点击了。");
  });
});
</script>
</head>
<body>
<p>点击这个段落。</p>
</body>
</html>

The above is the detailed content of What should I do if jquery does not support on?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How to get state in reactNext article:How to get state in react