Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
312 views
in Technique[技术] by (71.8m points)

javascript - anchor disappears so onClick event doesn't happen as it is faded out

I have an anchor (<a>) that appears only when an <input /> is focused. The moment the <input /> is blurred, the anchor's container fades out.

I'm trying to click on the anchor to trigger the onClick() event for it, but the moment I click, the focus changes, from the input, and the anchor's container disappears. I believe this is why when I click the anchor nothing happens.

How can I check on the blur event of the <input /> if the anchor was just clicked and that is what caused the focus to change from the <input /> and cause the blur event?

Then, if the blur event occurred because I clicked on the anchor, I can trigger the onClick() and if not, I can fade out the anchor's container.

How can I do this javascript / jQuery ?

Update:

I am currently trying to do the following in javascript:

On blur of input, if .ss-result a was not clicked then fade out, else alert(".ss-result a clicked!");

Here is the code that I am trying to accomplish this with, but it breaks my fading in of the anchor on focus of <input />. I'm not getting any console errors.

var inputObj = $('input');
var boxObj = $('.container');
inputObj.blur(function() {
    if($('.ss-result a').is(':focus')){
        alert(".ss-result a clicked!");)
    }
    else{
        boxObj.fadeOut(100);
    }
});
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...