Home > Web Front-end > JS Tutorial > body text

Jquery: Sample code sharing for change event and bind event

黄舟
Release: 2017-06-27 09:22:58
Original
1492 people have browsed it

Bind a handler function to the change event of each matching element. The change event is triggered when an element loses focus, and also when its value changes after gaining focus.

JqueryBasic syntax:

$("input[type='text']").change( function() { 
// 这里可以写你想要的验证代码; 
});
Copy after login

2 When binding a text box

$(function () { 
$("#txtAssessmentTotal").change(function () { 
//这里写你想要的验证的代码; 
}) 
})
Copy after login


is the specific value of each matching element Event bindingEvent handling function. The
.bind() method is the primary way to attach behavior to a document. All JavaScript event objects, such as focus, mouseover, and resize, can be passed in as the type parameter.
Personal understanding of bind is to bind the event for this control and define an anonymous method for this event to achieve the verification you want;
Jquery basic syntax:

$("#txtAssessmentTotal").bind('click', function() { 
alert($("#txtAssessmentTotal").val()); 
});
Copy after login


2 Multiple events: The names of the events are separated by spaces;

$("#txtAssessmentTotal").bind('mouseenter mouseleave', function() { 
alert($("#txtAssessmentTotal").val()); 
});
Copy after login


The above is the detailed content of Jquery: Sample code sharing for change event and bind event. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template