0

我的 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)。有人可以帮忙吗?谢谢! )

4

1 回答 1

1

工作 jsFiddle 演示

你的链接是:

<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
});
于 2013-05-25T08:49:39.560 回答