开发者

order of javascript events?

开发者 https://www.devze.com 2023-01-24 05:56 出处:网络
I have a \"a.adress\" element in a div. on blur, the div dissapears. Whenever I click the a.adress element, I want the value of the a element to populate a field.(the same that gets blurred.

I have a "a.adress" element in a div. on blur, the div dissapears. Whenever I click the a.adress element, I want the value of the a element to populate a field.(the same that gets blurred.

This is what I expected to work:

$('.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");
});

Each part works seperately,

this hides the div

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

this populates the field:

  $("a.adress").click(function() {
    event.preventDefault();
    $(this).parent().parent().parent().parent().prev(".field").val($(this).te开发者_运维问答xt());
  });

sample page: http://dev.resihop.nu/addtrip?from=&to=&when=&name=&email=&phone=&details=&posted=&got_car=1

But when I put them together, I don't manage to populate the label. How do I make it work?


Kristoffer,

based on the link you provided ...

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

... that should be sufficient.

0

精彩评论

暂无评论...
验证码 换一张
取 消