Jquery focus()和blur()对我的href不起作用.为什么

jquery focus() and blur() don't work for my href. why?

本文关键字:href 不起作用 为什么 我的 blur focus Jquery      更新时间:2023-09-26

我有一个链接在我的html:

<a id="mnRoles" href="SysRoles.aspx">Roles</a>

这里有更多的html:

<tr><td style="vertical-align:top;width:33%;">
<table cellpadding="0" cellspacing="0" class="MenuTable">
<tr><th>HRM</th></tr>
<tr><td><a id="mnRoles" href="SysRoles.aspx">Roles</a></td></tr>
<tr><td><a id="mnFunctions" href="SysFunctions.aspx">Function rights</a></td></tr>
<tr><td><a id="mnRegionalOptions" href="MenuCustomize.aspx">Regional options</a></td>    </tr>
</table></td></tr></table>
<script>sysPageUrl='logposmanagement.aspx'</script></form>
</body>
</html>

和我试图设置焦点到它(或模糊另一个)通过jQuery像这样:

<script>
$(document).ready(function(){
    $("#mnRoles").blur();
    $("#mnFunction").focus();
});
</script>

但它不起作用。知道为什么吗?提前感谢!

(我问这个问题的原因是:我希望在加载页面时将焦点设置为我选择的特定链接(通过jQuery)。我不能修改任何HTML或css)。有人能帮帮我吗?谢谢!)

Working jsFiddle Demo

你的链接是:

<a id="mnFunctions" href="SysFunctions.aspx">Function rights</a>

注意,id是mnFunctions,但在你的jQuery代码中,你写:

$("#mnFunction").focus();

此处id为mnFunction。你省略了最后的s。你必须这样写:

$(document).ready(function(){
    $("#mnRoles").blur();
    $("#mnFunctions").focus(); // note that the ID has an `s` at the end
});
  • 可以查看jsFiddle Demo