Home  >  Article  >  Web Front-end  >  Jquery: Sample code sharing for change event and bind event

Jquery: Sample code sharing for change event and bind event

黄舟
黄舟Original
2017-06-27 09:22:581443browse

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() { 
// 这里可以写你想要的验证代码; 
});

2 When binding a text box

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


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()); 
});


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

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


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!

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