Why i always get a value(bu0) of typing in 3 field different(class="bg_units bu0"
, class="bg_units bu1"
, class="bg_units bu2"
) ?
I want if user typing value in field bu0 get dynamic part 2 class="bg_units bu0"
of class (.bu0), as for other:开发者_运维问答
- if typing each value on field bu0 =get class=>
.bu0
- if typing each value on field bu1 =get class=>
.bu1
- if typing each value on field bu2 =get class=>
.bu2
EXAMPLE: http://jsfiddle.net/jJaYT/
$('.eghamat').live('keyup',function () {
var $this = $(this),
$div = $this.closest('div.find_input'),
bu_num = '.' + $div.find('.bg_units').attr('class').split(" ")[1];
alert(bu_num);
});
Your code should do this:
$('.eghamat').live('keyup', function() {
var $this = $(this),
$div = $this.closest('div.bg_units'),
bu_num = '.' + $div.attr('class').split(" ")[1];
alert(bu_num);
});
You are going up to the topmost div, which contains everything, searching for .bg_units
and always getting the first one. Just call $this.closest('div.bg_units'),
You just needed a small change:
Working example : http://jsfiddle.net/jJaYT/2/
$('.eghamat').live('keyup',function () {
$div = $(this).closest('.bg_units');
bu_num = '.' + $div.attr('class').split(" ")[1];
alert(bu_num);
});
精彩评论