asp.net中focus的做用

  首先說明下ASP.NET控件中focus的做用就是,將光標移動到控件中.好比下面作一個文本框的小例子,正常狀況下須要用戶將光標移動到文本框內輸入文本.可是使用focus就不一樣了,光標就直接移動到文本框內,直接輸入了.詳細請見下面代碼:
 Default.aspx:
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">web

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>無標題頁</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <fieldset>
        <legend>第一個網站</legend><div style="text-indent:10px">這段代碼的做用是使光標直接放到文本框中</div>
        <asp:TextBox ID="TextBoxName" runat="server" />
       
    </fieldset>
   
    </div>
    </form>
</body>
</html>測試

 
 


 Default.aspx.cs:
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;網站

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //將光標移動到文本框中.
        TextBoxName.Focus();
    }
}orm

 
 

就是這麼簡單,測試下吧.^_^server

 

本文轉自 ☆★ 一應俱全 ★☆ - www.baoluowanxiang.com 轉載請註明出處,侵權必究!
原文連接:http://www.baoluowanxiang.com/a/website/dotnet/2011/0421/3166.htmlxml

相關文章
相關標籤/搜索