简体   繁体   English

如何将注意力集中在控制上

[英]how to set focus on control

* ASP.NET VB.NET 2010 * ** * * ASP.NET VB.NET 2010 * ** *

Hi, KIndly help me with this, I have a list of Hyperlink.嗨,请帮我解决这个问题,我有一个超链接列表。 If I press radio button I want my cursor to focus on one of my hyperlink如果我按下单选按钮,我希望我的 cursor 专注于我的超链接之一

I tried to used this but no luck Dim sScript As String = "document.getElementById('" & hlnkQNo.ID & "').focus();"我尝试使用它但没有运气 Dim sScript As String = "document.getElementById('" & hlnkQNo.ID & "').focus();" 'Page.RegisterStartupScript("controlFocus", sScript) 'Page.RegisterStartupScript("controlFocus", sScript)

I also tried this but the same, the cursor was not focus on my link ScriptManager1.SetFocus(hlnkQNo.ID).我也试过这个,但同样,cursor 没有关注我的链接 ScriptManager1.SetFocus(hlnkQNo.ID)。

Here is my example of what I want Hyperlink1 Hyperlink2 Hyperlink3 Hyperlink3 Hyperlink4这是我想要的示例 Hyperlink1 Hyperlink2 Hyperlink3 Hyperlink3 Hyperlink4

if the use click the radio button i want to focus on Hyperlink4如果使用单击单选按钮我想专注于 Hyperlink4

Your question is difficult to understand, but generally if you want to focus an element you need to set an event handler on the radio button so that when it's clicked another element receives focus.你的问题很难理解,但通常如果你想聚焦一个元素,你需要在单选按钮上设置一个事件处理程序,以便在单击它时另一个元素获得焦点。

    document.getElementById("myRadioButton").click = function(){
        document.getElementById("Hyperlink1").focus();
    };

If your code is being generated server side with VB.NET, then you're going to have to figure out exactly how the snippet above should be rendered.如果您的代码是使用 VB.NET 在服务器端生成的,那么您将必须弄清楚上面的代码片段应该如何呈现。

just to provide an alternative , maybe you might want to consider using jquery to do those kind of things.只是为了提供替代方案,也许您可能想考虑使用 jquery 来做这些事情。

and as long as you put runat="server" on your control, you can still retrieve all the value or manipulate them on the server side.并且只要将 runat="server" 放在控件上,您仍然可以检索所有值或在服务器端操作它们。

<a href="http:www.yahoo.com">link 1</a>
<a href="http:www.yahoo.com">link 2</a>
<a href="http:www.yahoo.com">link 3</a>
<a href="http:www.yahoo.com">link 4</a>
<br />
<input type="radio" name="radio4" id="radio4" value="4" /> 4<br />

$(document).ready(function(){

    $("#radio4").click(function(){
        $("a:eq(3)").css('color','red');
        $("a:eq(3)").focus();
    });
});

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

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