如题

解决方案 »

  1.   

    不失去焦点就触发,是在什么时候触发? 按下ENTER键?还是别的键?如果以捕捉某一按键来触发,你可以用textbox的onkeyup(onkeypress..)来触发__doPostBack('txtboxid','')
      

  2.   

    <input onpropertychang="alert('x')">
    支持粘贴操作
      

  3.   

    <input onpropertychange="alert('x')">
      

  4.   

    是的,onkeyDown = "thisFunc(this)"
    function thisFunc(this)
    {
       if(event.keyCode!='13'&&event.keyCode!='9')
       {
          __doPostBack(this.id,'','');
       }
    }page_load时:添加函数page.registerClientScriptBlock("",thisTextBox.ClientID + ".focus();")
      

  5.   

    net_lover
    你所说的那个控件是html控件,在C#程序里面怎么进行操作呀
      

  6.   

    net_lover
    你所说的那个控件是html控件,在C#程序里面怎么进行操作呀//==>
    在客户端生成的也是html control
    cs:
    Textbox1.Attributes["onpropertychange"] = "thisFunc(this)";javascript:
    function thisFunc(this)
    {      
      __doPostBack(this.id,'',''); 
    }如果还想在TextChange事件(PostBack)后文本框还需要获取焦点, 就在TextBox的TextChange事件里加一句
    Page.RegisterStartupScript("", "<script>javascript:document.all.txtID.focus();</script>");
      

  7.   

    SVG(ben)
    现在可以触发了,但是焦点是停在textbox的最前,我如果要它停在textbox的最后面怎么办呀
      

  8.   

    <input onpropertychange="alert('x')">
      

  9.   

    把属性AutoPostBack =true然后你改变文本就会触发TextChange事件了。。
      

  10.   

    使用SVG(ben)的方法之后还要使用以下几句
    Page.RegisterStartupScript("go","<script language="javascript">NewFocus(document.all.thisTextBox)</script>")页面上加上
    <script language = "javascript">
    function NewFocus(TextBox)
    {
       TextBox.focus();
       var oTextRange = document.createTextRange();
       oTextRange.collapse(false);
       oTextRange.select(); 
    }这样就可以将光标定位到末尾了。
    </script>
      

  11.   

    上面的脚本写错了,应该是:
    function NewFocus(TextBox)
    {
       TextBox.focus();
       var oTextRange = TextBox.createTextRange();
       oTextRange.collapse(false);
       oTextRange.select(); 
    }
      

  12.   

    另外,ThisFunc必须这样写
    function thisFunc(this)
    {      
       if(event.keyCode==32||(event.keyCode>48&&event.keyCode<90))
       {
          __doPostBack(this.id,'','');
       } 
    }
    不然你会烦死的,移动光标都会回发。
      

  13.   

    dandantree
    为什么我写进去以后不行呀,老是提示缺少对象。在 TextBox.focus();这行
      

  14.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <TITLE></TITLE>
    <META content="Microsoft Visual Studio 7.0" name="GENERATOR">
    <SCRIPT ID="clientEventHandlersJS" LANGUAGE="javascript">
    <!--
    var index;
    function window_onload() {
    div1.style.left=Text1.offsetLeft;
    div1.style.top=Text1.offsetTop+24;
    div1.style.width=Text1.offsetWidth;
    index=0;
    }function Text1_onkeyup()
    {

    switch (window.event.keyCode)
    {
    case 13: 
    div1.style.visibility="hidden";
    break;
    case 40:
    case 39: 
    if (index < div1.childNodes.length) 
    {
    index=index+1;
    }
    for (i=1;i<=div1.childNodes.length;i++)
    {
    if (i==index)
    {
    Text1.value=div1.childNodes[index-1].innerText.substr(1);
    div1.childNodes[index-1].style.backgroundColor="lightblue";
    }
    else
    {
    div1.childNodes[i-1].style.backgroundColor="white";
    }
    }
    break;
    case 38:
    case 37: 
    if (index>1) 
    {
    index=index-1;
    }
    for (i=1;i<=div1.childNodes.length;i++)
    {
    if (i==index)
    {
    Text1.value=div1.childNodes[index-1].innerText.substr(1);
    div1.childNodes[index-1].style.backgroundColor="lightblue";
    }
    else
    {
    div1.childNodes[i-1].style.backgroundColor="white";
    }
    }
    break;
    default:
    index=0;

    div1.innerHtml ="";
    docSubmit = new ActiveXObject("MSXML2.DOMDocument");
    docSubmit.async = false;
    docSubmit.load("http://msft-chen/ASPTips2/CH1/SearchTitles.asmx/doSearch?keyword=" + Text1.value);

    docSubmit.loadXML(docSubmit.xml.replace(/&lt;/g,"<").replace(/&gt;/g,">"));

    //
    var s;
    s="";
    nodeList=docSubmit.documentElement.getElementsByTagName("Table");
    for (i=0;i<nodeList.length;i++)
    {
    s=s + "<div style=\"WIDTH:490px;\" class=\"gotTitle\" onmouseover=\"javascript:this.style.backgroundColor='lightblue'\" onmouseout=\"javascript:this.style.backgroundColor='white'\" onclick=\"return gotTitle_onclick()\">&nbsp;" + nodeList(i).selectSingleNode("title").text + "</div>";
    }
    div1.innerHTML=s;
    div1.style.visibility="visible";
    }
    }function gotTitle_onclick()
    {
    if (window.event.srcElement.className="gotTitle")
    {
    Text1.value=window.event.srcElement.innerText.substr(1);
    div1.style.visibility="hidden";
    }
    }function gotTitle_onblur()
    {
    div1.style.visibility="hidden";
    }//-->
    </SCRIPT>
    <style> .list{ BORDER-RIGHT:black 1px solid; BORDER-TOP:black 1px outset; BORDER-BOTTOM:black 1px solid; BORDER-LEFT:black 1px outset; FONT-SIZE:x-small; VISIBILITY:hidden; WIDTH:490px; HEIGHT:20px; CURSOR:default; POSITION:absolute; }
    </style>
    </HEAD>
    <BODY LANGUAGE="javascript" onload="return window_onload()">
    <P><FONT face="宋体">搜索图书:</FONT> <INPUT id="Text1" type="text" name="Text1" size="78" LANGUAGE="javascript" onkeyup="return Text1_onkeyup()">&nbsp;</P>
    <span id="div1" onblur="return gotTitle_onblur()" class="list"></span>
    <P><FONT face="宋体"></FONT></P>
    </BODY>
    </HTML>