What is jQuery event?

jQuery event function
jQuery jQuery event handler method is the core function.
Event handler method means that when certain events occur in the HTML call. Term by an event "trigger" (or "excitation") is often used.
It will usually put jQuery code portion of the event handler method:

<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("p").hide();
});
});
</script>
</head>

<body>
<h2>This is a heading</h2>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<button type="button">Click me</button>
</body>
</html> 

The method Hide all

Element:
$ ( "the p-") hide ();.

jQuery Name Conflicts
jQuery jQuery using the $ symbol as a way of introduction.
Some other JavaScript library functions (such as Prototype) also use the $ symbol.
jQuery using a method called noConflict () to resolve the problem.
var jq = jQuery.noConflict (), to help you use your own name (such as jq) instead of the $ symbol.

<!DOCTYPE html>
<html>
<head>
<script src="/jquery/jquery-1.11.1.min.js"></script>
<script>
$.noConflict();
jQuery(document).ready(function(){
  jQuery("button").click(function(){
    jQuery("p").text("jQuery 仍在运行!");
  });
});
</script>
</head>

<body>
<p>这是一个段落。</p>
<button>测试 jQuery</button>
</body>
</html>

Conclusion
Since jQuery is specially designed to handle HTML event, then when you follow these guidelines, your code will be more appropriate and easier to maintain:
all the jQuery code in the event handler
to all event handlers into the document ready event handler in
the jQuery code in a separate .js file
if there is a name conflict, rename the jQuery library.

Here are some examples in jQuery event method:
Event function to bind a function to
$ (document) .ready (function) binds a function to the event ready document (when the document is finished loading)
$ (Selector) .click (function) trigger or bind a function to the click event of the selected elements
$ (selector) .dblclick (function) or a trigger function to bind to double-click on the selected elements of the event
$ (selector) .focus (function) or binds a function trigger to get the focus event of selected elements
$ (selector) .mouseover (function) or a trigger function to bind mouseover event of selected elements

Published 74 original articles · won praise 27 · views 9510

Guess you like

Origin blog.csdn.net/qq_42526440/article/details/102014550