Javascript的焦点问题

Javascript的焦点问题,javascript,html,css,Javascript,Html,Css,我有一个选择选项,单击后,它会将表单属性从display:none更改为display:block,并将windows.hash更改为其他内容,但是在Chrome中,视图会自动向下滚动并聚焦表单。你如何防止这种行为 function mainTypeChange(element){ if ("business" == element.options[element.selectedIndex].value) { window.location.hash = "busine

我有一个选择选项,单击后,它会将表单属性从display:none更改为display:block,并将windows.hash更改为其他内容,但是在Chrome中,视图会自动向下滚动并聚焦表单。你如何防止这种行为

function mainTypeChange(element){
    if ("business" == element.options[element.selectedIndex].value) {
        window.location.hash = "business";
    } else {
        document.getElementById("requestQuote").style.display = 'block';    
        window.location.hash = "requestQuote";
    }
}

也许你会发现pushState很有帮助。查看它自动滚动的文档,因为您更改了它的哈希值,这里的哈希表示您要导航到的片段,它是URL中以符号开头的部分。为了防止它,您可以插入return false;将链接上的事件绑定为时,请记住使用e.preventDefault;。例如:$element.on'click',function{e.preventDefault;//您在这里工作吗//;}