Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
315 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 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...