Hello actually I have an div tag in which there are multiple form. What I want is to apply onChange event on the div for each input field. Present I am trying this
Applying form class to each form and getting onchange event
$('.form :input').change(function(e){
console.log("Element changed");
});
But I am not able to get the info which field is changed and what is the updated value.
So can I apply it on the div itself? If not how can the get the field info which is changed.
Hello actually I have an div tag in which there are multiple form. What I want is to apply onChange event on the div for each input field. Present I am trying this
Applying form class to each form and getting onchange event
$('.form :input').change(function(e){
console.log("Element changed");
});
But I am not able to get the info which field is changed and what is the updated value.
So can I apply it on the div itself? If not how can the get the field info which is changed.
Share Improve this question edited Feb 3, 2014 at 11:56 harpax 6,1165 gold badges37 silver badges49 bronze badges asked Feb 3, 2014 at 11:52 Nikhil AgrawalNikhil Agrawal 26.6k21 gold badges93 silver badges127 bronze badges1 Answer
Reset to default 3Try this:
$(function(){
$('.form :input').change(function(e){
console.log($(e.target).attr('id'));
});
});
here e.target
is your current element which got the event of change
.
As per your ment:
How we can say which field is changed.
you need to assign an unique identifier to all your input type text
:
<input type='text' id='a'>
<input type='text' id='b'>
..................
then use this:
$('.form :input').change(function(e){
$('#log').prepend('<p>Form changed ' + $(e.target).attr('id') + '</p>')
});
A demo of your fiddle here.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745102205a4611341.html
评论列表(0条)