如何在jquery中刷新后保持对文本字段的关注

如何在jquery中刷新后保持对文本字段的关注,jquery,html,asp-classic,ado,Jquery,Html,Asp Classic,Ado,刷新后如何保持文本字段的焦点?我有一个代码,当用户停止键入并在此时提交表单时,它会自动检测。但如果用户希望继续键入,则必须再次单击文本框 此外,如果他们正在执行的查询没有结果,那么文本字段中的值(文本)将被删除。我已经做了好几个小时了。任何帮助都将不胜感激 Jquery代码: <script> $(document).ready(function() { $("#cat").change(function () { this.form.submit(); }) va

刷新后如何保持文本字段的焦点?我有一个代码,当用户停止键入并在此时提交表单时,它会自动检测。但如果用户希望继续键入,则必须再次单击文本框

此外,如果他们正在执行的查询没有结果,那么文本字段中的值(文本)将被删除。我已经做了好几个小时了。任何帮助都将不胜感激

Jquery代码:

<script>
$(document).ready(function() {
    $("#cat").change(function () {
    this.form.submit();
})

var typingTimer;                //timer identifier
var doneTypingInterval = 1000;  //time in ms, 5 second for example

//on keyup, start the countdown
$('#legal').keyup(function(){
    clearTimeout(typingTimer);
    if ($('#legal').val) {
        typingTimer = setTimeout(doneTyping, doneTypingInterval);
    }
});

//user is "finished typing," do something
function doneTyping () {
    $("form").submit();
}

});
</script>

$(文档).ready(函数(){
$(“#cat”).更改(函数(){
这个.form.submit();
})
var typingTimer;//计时器标识符
var doneTypingInterval=1000;//以毫秒为单位的时间,例如5秒
//在键控启动时,开始倒计时
$('#legal').keyup(函数(){
clearTimeout(键入计时器);
if($('#legal').val){
typingTimer=setTimeout(doneTyping,doneTypingInterval);
}
});
//用户正在“完成键入”,请执行某些操作
函数doneTyping(){
$(“表格”)。提交();
}
});
页面代码:

<%@ LANGUAGE="VBSCRIPT" %>
<%
pagetitle="Contractor Details"
%>
<!--#INCLUDE VIRTUAL="/_lib/include/header.htm"-->
<!--#INCLUDE VIRTUAL="/_lib/include/menu.htm"-->
<script>
$(document).ready(function() {
    $("#cat").change(function () {
    this.form.submit();
})

var typingTimer;                //timer identifier
var doneTypingInterval = 1000;  //time in ms, 5 second for example

//on keyup, start the countdown
$('#legal').keyup(function(){
    clearTimeout(typingTimer);
    if ($('#legal').val) {
        typingTimer = setTimeout(doneTyping, doneTypingInterval);
    }
});

//user is "finished typing," do something
function doneTyping () {
    $("form").submit();
}

});
</script>
<div class="twoColumnRow">
<div class="twoColumnContent">
<p class="breadCrm"><a href="/index.htm">Home</a> <span>&gt;</span> <a href="/tools/index.htm">Tools of the Trade</a> <span>&gt;</span> <a href="/tools/finance/index.htm">Finance and Purchasing</a><span>&gt;</span> <a href="/tools/finance/procurement/index.htm">Procurement and Contracts information</a></p>
<div class="contentPad">
<!-- Start of main content -->

<p class="imageRight">&nbsp;</p>
<h1><%=pagetitle%></h1>

<%
        Dim connectString, connect, conDB, sconDB, lDB, con, scon, lcon, src_abn, src_cat
        connectString = "Driver={Microsoft Text Driver (*.txt; *.csv)}; DBQ=" & Server.MapPath("data")
              src_legal = Request.QueryString("legal")
              src_cat = Request.QueryString("cat")
        set connect = Server.CreateObject("ADODB.connection")
        connect.open connectString

        if src_cat = "all" then
        conDB = "SELECT * FROM cont.csv WHERE ucase(legal) LIKE ucase('%"+src_legal+"%')"   
        lDB = "SELECT * FROM cont.csv WHERE ucase(legal) LIKE ucase('%"+src_legal+"%')" 
        else 
        conDB = " SELECT * FROM cont.csv WHERE " & src_cat & " = 'Yes' AND ucase(legal) LIKE ucase('%"+src_legal+"%')"
        lDB = " SELECT * FROM cont.csv WHERE " & src_cat & " = 'Yes' AND ucase(legal) LIKE ucase('%"+src_legal+"%')"
        end if

        sconDB = "SELECT * FROM cont.csv"   

        set con = connect.execute(conDB)
        set scon = connect.execute(sconDB)
        set lcon = connect.execute(lDB)
%>
<h2>Search results</h2>
<% if not con.BOF then %>
<div style="margin-top:1em">

  <form id="searchf" action="dbinstant.htm" method="get">

      <p>Company name:1<br/>
      <input id="legal" name="legal" type="text" value="<%=src_legal%>">
      </p>
     <p>Categories for Creative Design:<br/>
      <select id="cat" name="cat">
        <option class="group" label="All categories" value="all" <%if request.querystring("cat") = "all" then response.write("selected") %>></option>
        <option class="group" label="Strategic brand, marketing and communications advice" value="a" <%if request.querystring("cat") = "a" then response.write("selected") %>></option>
        <option class="group" label="Graphic design and layout" value="b" <%if request.querystring("cat") = "b" then response.write("selected") %>></option>
        <option class="group" label="Forms design" value="c" <%if request.querystring("cat") = "c" then response.write("selected") %>></option>
        <option class="group" label="Web design and development" value="d" <%if request.querystring("cat") = "d" then response.write("selected") %>></option>
        <option class="group" label="Authoring services" value="e" <%if request.querystring("cat") = "e" then response.write("selected") %>></option>
        <option class="group" label="Editorial services" value="f" <%if request.querystring("cat") = "f" then response.write("selected") %>></option>
        <option class="group" label="Translation services" value="g" <%if request.querystring("cat") = "g" then response.write("selected") %>></option>
        <option class="group" label="Photography and film services" value="h" <%if request.querystring("cat") = "h" then response.write("selected") %>></option>
        <option class="group" label="Scanning and digitisation services" value="i" <%if request.querystring("cat") = "i" then response.write("selected") %>></option>
        <option class="group" label="Multimedia editing services" value="j" <%if request.querystring("cat") = "j" then response.write("selected") %>></option>
      </select>
    </p>
    <input type="submit" value="Search" />
  </form>
  <br />

    <table style="font-size:.9em;" class="contentTable">
          <tr>
                <th>ABN:</th>
                <th>Company Name:</td>
          </tr>
  <% con.Movefirst() %>
  <% while (NOT con.EOF) %>
          <tr>
                <td width="120px"><%=con("abn")%></th>
                <td><a href="dbcomp.htm?abn=<%=con("abn")%>&cat=all"><%=con("legal")%></a></td>
          </tr>
  <%
    con.MoveNext()
    Wend
  %>
</table>

</div>
<% else %>
    <% scon.Movefirst() %>
  <form action="dbinstant.htm" method="get">

      <p>Company name:2<br/>
      <input id="legal" name="legal" type="text">
      </p>

     <p>Categories for Creative Design:<br/>
      <select id="cat" name="cat">
        <option class="group" label="All categories" value="all" <%if request.querystring("cat") = "all" then response.write("selected") %>></option>
        <option class="group" label="Strategic brand, marketing and communications advice" value="a" <%if request.querystring("cat") = "a" then response.write("selected") %>></option>
        <option class="group" label="Graphic design and layout" value="b" <%if request.querystring("cat") = "b" then response.write("selected") %>></option>
        <option class="group" label="Forms design" value="c" <%if request.querystring("cat") = "c" then response.write("selected") %>></option>
        <option class="group" label="Web design and development" value="d" <%if request.querystring("cat") = "d" then response.write("selected") %>></option>
        <option class="group" label="Authoring services" value="e" <%if request.querystring("cat") = "e" then response.write("selected") %>></option>
        <option class="group" label="Editorial services" value="f" <%if request.querystring("cat") = "f" then response.write("selected") %>></option>
        <option class="group" label="Translation services" value="g" <%if request.querystring("cat") = "g" then response.write("selected") %>></option>
        <option class="group" label="Photography and film services" value="h" <%if request.querystring("cat") = "h" then response.write("selected") %>></option>
        <option class="group" label="Scanning and digitisation services" value="i" <%if request.querystring("cat") = "i" then response.write("selected") %>></option>
        <option class="group" label="Multimedia editing services" value="j" <%if request.querystring("cat") = "j" then response.write("selected") %>></option>
      </select>
    </p>
    <input type="submit" value="Search" />
  </form>
  <br /><hr />
<p>No records match your query.</p>
<p><a href="dbtest.htm">Return to search page</a></p>
<%
  end if
  con.close
%>


<!-- End of main content -->
</div> <!-- end contentPad div -->
</div> <!-- end twocolumncontent div -->
<div class="twoColumnLinks">

<!--<div class="relatedLinks">
<h3>Related Links</h3>
<ul>
<li><a href="/index.htm">Related link 1</a></li>
</ul>
</div>--> <!-- end relatedlinks div -->
<!--#INCLUDE VIRTUAL="/_lib/include/quicklinks.htm"-->
<!--#INCLUDE VIRTUAL="/_lib/include/mylinks.htm"-->
</div> <!-- end twocolumnlinks div -->
</div> <!-- end twocolumnrow div -->
<!--#INCLUDE VIRTUAL="/_lib/include/footer.htm"-->

$(文档).ready(函数(){
$(“#cat”).更改(函数(){
这个.form.submit();
})
var typingTimer;//计时器标识符
var doneTypingInterval=1000;//以毫秒为单位的时间,例如5秒
//在键控启动时,开始倒计时
$('#legal').keyup(函数(){
clearTimeout(键入计时器);
if($('#legal').val){
typingTimer=setTimeout(doneTyping,doneTypingInterval);
}
});
//用户正在“完成键入”,请执行某些操作
函数doneTyping(){
$(“表格”)。提交();
}
});

搜索结果 公司名称:1

创意设计类别:


荷兰银行: 公司名称: 公司名称:2

创意设计类别:



没有与您的查询匹配的记录

您可以对要放置文本光标的元素调用focus()事件。例如:在您的body onload部分放置$(“#legal”).focus()

请重试:

$(document).ready(function() {
    $("#cat").focus();
    $("#cat").val($("#cat").val());
    $("#cat").change(function () {
        this.form.submit();
    });
});

你试过把
$('#legal').focus()放进去吗?这是一个jquery/html问题,不是SQL。删除了有效的
sql
标记,但当您键入时焦点处于打开状态时,它会删除以前的内容。是否有一种方法可以在当前文本字段中的文本之后开始键入?这是可行的,但当您键入时焦点处于打开状态时,它会删除以前的内容。有没有办法在当前文本字段中的文本之后开始键入?老实说,我认为您的解决方案的设计不是很好。不是每次发布(并重新加载整个页面),而是应该考虑使用Ajax调用对服务器进行部分往返访问来保存数据。这样你就可以避免中断用户交互。我怎样才能得到一个部分总结?你能给我一些具体的资源,这将有助于堆。谢谢这是可行的,但是当你输入焦点时,它会删除以前的内容。是否有方法在文本字段中当前的文本之后开始键入?