简体   繁体   English

专注于用户控制

[英]focus on user control

I want to focus on a user control but it is giving me errors我想专注于用户控件,但它给了我错误

function getFocus() {
    document.getElementById('<%myUserControl.ClientID%>').focus()
}
<a href....  onclick="getFocus()>Click</a>

How can i do this?我怎样才能做到这一点?

Thank you谢谢

Replace this:替换这个:

document.getElementById('<%myUserControl.ClientID%>').focus()

with this:有了这个:

document.getElementById('<%= myUserControl.ClientID%>').focus()

<%=myUserControl.ClientID%> missing "=" <%=myUserControl.ClientID%> 缺少“=”

I am not sure of that which component you want to focus on.我不确定您要关注哪个组件。 If you want to focus on the "Rates".如果您想专注于“费率”。 Based on the code you posted on the other question, I suggest you change your code to.根据您在另一个问题上发布的代码,我建议您将代码更改为。

<a id="p2" href="#" runat="server">Rates</a>

: remove the lable and then add href to do what you want to do here. :删除标签,然后添加 href 以在此处执行您想要执行的操作。 and then in your javascript: document.getElementById("<%=p2.ClientID%>").focus();然后在你的 javascript 中: document.getElementById("<%=p2.ClientID%>").focus();

then you can get Rates focus.然后你可以得到利率焦点。

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

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