2014-04-16 38 views
0

我有一些显示/隐藏选择菜单的文本字段。发生这种情况时,正在监视文本字段值的更改的脚本无法正确启动。出于某种原因,它并没有注意到这一变化。当选择菜单更改时,执行以下jquery代码

脚本:

var somethingChanged = false; 
$(document).ready(function(){ 
    $('input, select').change(function() { 
     somethingChanged = true; 
     console.log($(this).attr('name')+ ' has changed'); 

$('input[class*=input]').focus(function() { 
    if ($(this).hasClass('left')) { 
    $(this).parent().addClass("lightOverlay"); 
    console.log($(this).attr('name')+ ' added lightOverlay'); 
    } 
}).blur(function() { 
    if (this.value == ''){ 
     $(this).parent().removeClass('lightOverlay') 
     console.log($(this).attr('name')+ ' removed lightOverlay'); 
    } 
}) 

$('input[class*=input]').focus(function() { 
    if ($(this).hasClass('right')) { 
    $(this).parent().addClass("lightOverlayRight"); 
    console.log($(this).attr('name')+ ' added lightOverlayRight'); 
    } 
}).blur(function() { 
    if (this.value == ''){ 
     $(this).parent().removeClass('lightOverlayRight') 
    console.log($(this).attr('name')+ ' removed lightOverlayRight'); 
    } 
}) 
}) 
}); 

我怎么能执行此代码时,选择菜单的变化?

这里是有问题的网站与全码: http://2plygraphics.com/im-here/

,你会看到在网站上,如果您添加值3名,然后将其设置为7名的名字右边不正确应用背景图像,直到您点击它们...我想让代码检查选择菜单更改并相应地更新背景。

我想改变它的东西是这样的(基本上包住整个事情被点击选择菜单时调用函数):

var somethingChanged = false; 
$(document).ready(function(){ 

    $('select').click (function() { 
    $('input, select').change(function() { 
     somethingChanged = true; 
     console.log($(this).attr('name')+ ' has changed'); 

$('input[class*=input]').focus(function() { 
    if ($(this).hasClass('left')) { 
    $(this).parent().addClass("lightOverlay"); 
    console.log($(this).attr('name')+ ' added lightOverlay'); 
    } 
}).blur(function() { 
    if (this.value == ''){ 
     $(this).parent().removeClass('lightOverlay') 
     console.log($(this).attr('name')+ ' removed lightOverlay'); 
    } 
}) 

$('input[class*=input]').focus(function() { 
    if ($(this).hasClass('right')) { 
    $(this).parent().addClass("lightOverlayRight"); 
    console.log($(this).attr('name')+ ' added lightOverlayRight'); 
    } 
}).blur(function() { 
    if (this.value == ''){ 
     $(this).parent().removeClass('lightOverlayRight') 
    console.log($(this).attr('name')+ ' removed lightOverlayRight'); 
    } 
}) 
}) 
    }); 
}); 

,但似乎并没有工作....诺布中央在这里!请帮忙!

回答

0

你有没有试过textinput的keyup?

例如

$('input[type=text]').keyup(function() { 
+0

是的,我试过了,它只是第一次点击后的工作,甚至没有在初始场进入KEYUP。 – sventizzle

相关问题