简体   繁体   English

jQuery focus()和blur()对我的href不起作用。 为什么?

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

i have a link in my html: 我的html中有一个链接:

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

here is more html: 这里是更多的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>

and i'm trying to set focus to it (or blur another one) through jQuery like this: 我正在尝试通过jQuery将焦点设置为它(或模糊另一个):

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

but it doesn't work. 但这不起作用。 any ideea why? 任何想法为何? thanks in advance! 提前致谢!

(the reason i'm asking this: i want the focus to be set to a specific link of my choice when the page is loaded (through jQuery. i can't modify any html or css). could someone please help? thanks!) (我问这个的原因:我想在页面加载时将焦点设置为我选择的特定链接(通过jQuery。我无法修改任何HTML或CSS)。有人可以帮忙吗?谢谢! )

Working jsFiddle Demo 工作jsFiddle演示

Your link is: 您的链接是:

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

Note that the id is mnFunctions , but in your jQuery code, you wrote: 注意,id是mnFunctions ,但是在您的jQuery代码中,您写道:

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

Here, the id is mnFunction . 在这里,id是mnFunction You omitted the s at the end. 你省略了s底。 You must write this: 您必须这样写:

$(document).ready(function(){
    $("#mnRoles").blur();
    $("#mnFunctions").focus(); // note that the ID has an `s` at the end
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM