2010-11-05 79 views
1

我在div中有一個「a.adress」元素。模糊,div消失。每當我點擊a.adress元素,我想一個元素的值來填充字段(即變得模糊同JavaScript事件的順序?

這是我所期待的工作:。

$('.field').blur(function() { 
    $("a.adress").click(function() { 
    event.preventDefault(); 
    $(this).parent().parent().parent().parent().prev(".field").val($(this).text()); 
    }); 
    $(this).next('.spacer').children().removeClass("visible"); 
}); 

每個部分工作seperately,

這個隱藏在div

$('.field').blur(function() { 
    $(this).next('.spacer').children().removeClass("visible"); 
}); 

這個填充字段:

$("a.adress").click(function() { 
    event.preventDefault(); 
    $(this).parent().parent().parent().parent().prev(".field").val($(this).text()); 
    }); 

示例頁面: http://dev.resihop.nu/addtrip?from=&to=&when=&name=&email=&phone=&details=&posted=&got_car=1

但是,當我把它們放在一起,我不設法填充標籤。我如何使它工作?

回答

0

的Kristoffer,

根據您所提供的鏈接...

$('.field').blur(function() { 
    $(this).next('.spacer').children().removeClass('visible'); 
}); 

$('a.adress').click(function(e) { 
    var $this = $(this); 

    e.preventDefault(); 
    $this.parents('.spacer').prev('.field').val($this.text()); 
}); 

...這應該是足夠的。

+0

否:/問題是a標籤位於被隱藏的元素中! – Himmators 2010-11-06 10:16:59