:input [type ='text']选择器正在影响链接标签<a> in JQuery

时间:2018-11-27 19:54:58

标签: javascript jquery

I have bootstrap form in my website when a user focus on textfield the page don't scroll to view so i found this JQuery code and apply it

$(":input[type='text']").focus(function () {
        var e = $(this);
        $("html, body").animate({
            scrollTop: e.offset().top - 100
        }, 400)

it is working but it is also affecting the links in the page

<a href="/login">create your account.</a>

when i click the link it does the scroll to the top of the page if i click it again it goes to the login page. I have to click the link two times to go the login page.

did i miss something? as i know my Jquery code is obviously selecting input of type text why it is affecting the tags

1 个答案:

答案 0 :(得分:0)

我刚刚使用此post

找到了解决方案

我将事件从focus更改为click,它解决了我的问题。

有什么解释吗?