簡體   English   中英

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

[英]how to set focus on control

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

嗨,請幫我解決這個問題,我有一個超鏈接列表。 如果我按下單選按鈕,我希望我的 cursor 專注於我的超鏈接之一

我嘗試使用它但沒有運氣 Dim sScript As String = "document.getElementById('" & hlnkQNo.ID & "').focus();" 'Page.RegisterStartupScript("controlFocus", sScript)

我也試過這個,但同樣,cursor 沒有關注我的鏈接 ScriptManager1.SetFocus(hlnkQNo.ID)。

這是我想要的示例 Hyperlink1 Hyperlink2 Hyperlink3 Hyperlink3 Hyperlink4

如果使用單擊單選按鈕我想專注於 Hyperlink4

你的問題很難理解,但通常如果你想聚焦一個元素,你需要在單選按鈕上設置一個事件處理程序,以便在單擊它時另一個元素獲得焦點。

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

如果您的代碼是使用 VB.NET 在服務器端生成的,那么您將必須弄清楚上面的代碼片段應該如何呈現。

只是為了提供替代方案,也許您可能想考慮使用 jquery 來做這些事情。

並且只要將 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